admin 管理员组

文章数量: 1184232

public class MainActivity extends Activity {
 
	private MyReceiver receiver;
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.activity_main);
 
		receiver = new MyReceiver();
		IntentFilter homeFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
 
		registerReceiver(receiver, homeFilter);
	}
 
	@Override
	public void onDestroy() {
		unregisterReceiver(receiver);
		super.onDestroy();
	}
 
	private class MyReceiver extends BroadcastReceiver {
 
		private final String SYSTEM_DIALOG_REASON_KEY = "reason";
		private final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
		private final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
 
		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
				String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
 
				if (reason == null)
					return;
 
				// Home键
				if (reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
					Toast.makeText(getApplicationContext(), "按了Home键", Toast.LENGTH_SHORT).show();
				}
 
				// 最近任务列表键
				if (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
					Toast.makeText(getApplicationContext(), "按了最近任务列表", Toast.LENGTH_SHORT).show();
				}
			}
		}
	}
}

转载自:

本文标签: 键变身任 定制新体 让你的