屏蔽recent按键:
<uses-permission android:name="android.permission.REORDER_TASKS" />
@Override protected void onPause() { super.onPause(); ActivityManager activityManager = (ActivityManager) getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); activityManager.moveTaskToFront(getTaskId(), 0); }
开机自启动:
/** * Created by Zzm_Pc on 2017/3/28. */ public class BootBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.i("selftoactive", intent.getAction()); if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { Log.i("selftoactive", intent.getAction()); Toast.makeText(context, "开机自启动!!!", Toast.LENGTH_SHORT).show(); Intent intent1 = new Intent(context, FirstActivity.class); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//这个是重点,没有设置这个,app不会启 动,而且开机后有延迟几秒才会收到,开 机发送过来的信号 context.startActivity(intent1); } } }
<receiver android:name="com.lgkj.meicqt.utils.BootBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
Home按键,Recent按键的监听可以用广播:Recent按键类似
/** * Created by Zzm_Pc on 2017/3/28. */ public class HomeKeyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Log.i("homekey1", action); if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { Log.i("homekey1", action); String reason = intent.getStringExtra("reason"); Log.i("homekey1", reason); if ("homekey".equals(reason)) { //按下home键时的情况下 //do nothing just 拦截事件 Log.i("homekey1", "do nothing else xixi~~"); } } } }