安卓开机自启动demo

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" />

RECEIVE_BOOT_COMPLETED系统启动完成广播

DISABLE_KEYGUARD允许程序禁用键盘锁



安卓开机自启动demo,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。