创建一个接收器,用来接收android起机的广播,如:
?
package com.autoStart;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;public class Start extends BroadcastReceiver { private static final String TAG = "Start"; @Override public void onReceive(Context context, Intent intent) { Log.i(TAG,"System is starting .................................."); Intent i = new Intent(context,Main.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); // Intent s=new Intent(context,XXXService.class);// context.startService(s); }}
?
?
给AndroidManifest.xml加上声明,如:
?
?
<receiver android:name=".Start" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter></receiver>
?加上权限
?
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
?完事。
?