原文:http://blog.csdn.net/kevinmeng_ini58/article/details/7700786
片段一:
- <!-- 开机启动 -->
- <receiver android:name=".AutoStartReceiver">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED"/>
- <category android:name="android.intent.category.HOME"/>
- </intent-filter>
- </receiver>
android:name=".AutoStartReceiver"为处理开机启动后所做操作的AutoStartReceiver.java
片段二:在4.X版本上测试必须加入该句,测试设备原道N90 8G
- <!-- 开机启动 -->
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
片段三:AutoStartReceiver.java
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- /**
- * 实现开机启动
- * @author Owner
- */
- public class AutoStartReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- Intent i = new Intent(context, MainActivity.class);
- i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(i);
- }
- }