安卓开机自启动demo
- - CSDN博客移动开发推荐文章context.startActivity(intent);//启动意图. manifest.xml配置. RECEIVE_BOOT_COMPLETED系统启动完成广播. DISABLE_KEYGUARD允许程序禁用键盘锁. 作者:u010794950 发表于2014-5-21 14:28:17 原文链接.
package com.example.openstart; import android.app.KeyguardManager; import android.app.KeyguardManager.KeyguardLock; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class MPUStartBroadcastReceiver extends BroadcastReceiver { /** * 接收系统启动完成广播 * */ @Override public void onReceive(Context context, Intent intent) { //取消系统锁屏 KeyguardManager mKeyguardManager = (KeyguardManager)context.getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock mKeyguardLock = mKeyguardManager.newKeyguardLock("MainActivity"); mKeyguardLock.disableKeyguard(); intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);//启动意图 } }
manifest.xml配置
注册接收系统启动广播
<receiver android:name="com.example.openstart.MPUStartBroadcastReceiver" > <intent-filter android:priority="2147483647" > <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.HOME" > </category> </intent-filter> </receiver>权限添加
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
DISABLE_KEYGUARD允许程序禁用键盘锁