android开机自动启动APP(用BroadcastReceive实现)

1、新建一个继承BroadcastReceive的类

public class StartBoot extends BroadcastReceiver {

    public StartBoot() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        
        Intent intent2 = new Intent(context,MainActivity.class);//
        
        intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//
        context.startActivity(intent2);

    }

}

 

2.修改AndroidManifest.xml

  <receiver android:name=".StartBoot">
            <intent-filter >
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <category android:name="android.intent.category.HOME"/>
            </intent-filter>
        </receiver>

 

3、添加权限

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

 

posted @ 2014-10-27 20:56  stallran  阅读(328)  评论(0编辑  收藏  举报