码迷,mamicode.com
首页 > 移动开发 > 详细

安卓开机自启动demo

时间:2014-05-23 00:05:56      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:android   blog   class   c   code   java   

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,布布扣,bubuko.com

安卓开机自启动demo

标签:android   blog   class   c   code   java   

原文地址:http://blog.csdn.net/u010794950/article/details/26471453

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!