Android 屏蔽recent按键 ,Home按键,Recent按键的监听可以用广播,还有开机启动app...

屏蔽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~~");
            }
        }
    }
}

转载于:https://my.oschina.net/u/2987490/blog/869255

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值