另类方法屏蔽Android4.03的HOME按键

        <activity

            android:name="com.XXX.android.system.EmptyHome"

            android:label="@string/app_name"

            android:theme="@android:style/Theme.NoDisplay" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />



                <category android:name="android.intent.category.DEFAULT" />

                <category android:name="android.intent.category.HOME" />

            </intent-filter>

        </activity>
package com.XXX.android.system;



import java.util.List;



import android.app.Activity;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.content.pm.ResolveInfo;

import android.os.Bundle;

import android.widget.Toast;



/**

 * 有了厂家的支持,放弃此另类屏蔽HOME键做法。

 * 

 * @author AsionTang

 * @date 2013年3月13日 14:48:44

 */

@Deprecated

public class EmptyHome extends Activity

{

    public static boolean isExited = true;



    @Override

    protected void onCreate(final Bundle savedInstanceState)

    {

	super.onCreate(savedInstanceState);



	if (isExited)

	{

	    final PackageManager packageManager = this.getPackageManager();

	    final Intent intent = new Intent(Intent.ACTION_MAIN);

	    intent.addCategory(Intent.CATEGORY_HOME);

	    final List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

	    for (int i = 0; i < list.size(); i++)

	    {

		final String name = list.get(i).activityInfo.packageName;

		if (!"EmptyHome".equals(name))

		{

		    intent.setPackage(name);

		    break;

		}

	    }

	    this.startActivity(intent);



	    Toast.makeText(this, "HOME", Toast.LENGTH_SHORT).show();

	}

	this.finish();

    }

}

  

 

 

你可能感兴趣的:(Android4.0)