Android 开机启动

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.a51_boot_receiver">
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
            android:launchMode="singleInstance">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver
            android:name=".BootReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>
    </application>

</manifest>


public class BootReceiver extends BroadcastReceiver {
    //当手机重新启动的时候调用
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.
//        throw new UnsupportedOperationException("Not yet implemented");
        // 在这个方法里面开启Activity
        Intent intent2 = new Intent(context, MainActivity.class);

        //***注意 不能再广播接收者里面直接开启Activity 需要添加一个标记 添加一个任务栈的标记
        intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        // 开启Activity
        context.startActivity(intent2);
    }
}


关于应用屏蔽home键的问题,android4.0之后就不能用了:

分两个级别吧,
系统级的改源码,这个肯定没问题,但是我们写的APP都是应用级的肯定不能改。
如果单纯的只是屏蔽home键在应用级是不可能,但是目前的解决方法可以采用一些变通的方式。比如现在百度锁屏是屏蔽了home键的,当然并不是真的屏蔽了home键,而是点击了home之后修改系统的桌面为锁屏界面,这样当然也就实现了锁屏的效果。

http://bbs.csdn.net/topics/391909596?page=1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值