1.要做的就是監聽系統發出的broadcast
public class FlorenceText extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
start(context);
}
}
}
2.在AndroidMenifest.xml裡還要將receiver加上, 並寫明程序的入口就是FlorenceTest
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name=".main.FlorenceTest"
android:exported="true"
android:process=":remote">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
</application>
這樣,程序就可以在開機時自動運行瞭
摘自 wenlibin1985的專欄