开机自动启动(android.intent.action.BOOT_COMPLETED、BroadcastReceiver)

mainfest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.huanglifeng.myapplication01"
android:versionCode="1"
android:versionName="1.0"
>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".StartupReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME"></category>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

</manifest>

--------------------------

package com.example.huanglifeng.myapplication01;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
* Created by huanglifeng on 2015/7/16.
*/
public class StartupReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context,Intent intent)
{
Intent mainIntent=new Intent(context,MainActivity.class);
mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mainIntent);
}
}

你可能感兴趣的:(开机自动启动(android.intent.action.BOOT_COMPLETED、BroadcastReceiver))