`

监听 home 键

 
阅读更多

监听HOME键的文章:http://dev.10086.cn/cmdn/bbs/thread-61702-1-1.html

 

 

http://blog.csdn.net/tjd0227/article/details/5601941

 

 

http://blog.csdn.net/JavaTiger427/article/details/6149501

 

http://www.chinese-it.com/plus/view-3611-1.html

http://blog.163.com/whatwhyhow@126/blog/static/133422389201131811752268/

 

public class HomeListenerActivity extends Activity {
	private HomeReceiver homeReceiver = new HomeReceiver();
	private IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        registerReceiver(homeReceiver, intentFilter);
    }
    
    
    public class HomeReceiver extends BroadcastReceiver{

		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			Log.d("test", "__action____" + action);
			
			if(!TextUtils.isEmpty(action)){
				if(action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)){
					String reason = intent.getStringExtra("reason");
					
					if(reason != null){
						if(reason.equals("homekey")){
							
						}else if(reason.equals("recentapps")){
							
						}
					}
				}
			}
			
		}
    }


	@Override
	protected void onDestroy() {
		super.onDestroy();
		unregisterReceiver(homeReceiver);
	}
    
    
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics