<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之后修改系统的桌面为锁屏界面,这样当然也就实现了锁屏的效果。