问题
How can I make my application to get started while my phone boots up itself.
回答1:
You need to use a BroadcastReceiver
with android.intent.action.BOOT_COMPLETED
intent.
Add following to your manifest file:
<receiver android:name="MyApp_Receiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
MyApp_Receiver class implementing BoradcastReciever. Implement the onReceive() method and start your favorite activity from your app.
public void onReceive(Context context, Intent intent) {
// make sure you receive "BOOT_COMPLETED"
if ((intent.getAction() != null) && (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")))
{
// Start the service or activity
}
}
来源:https://stackoverflow.com/questions/3618114/autostart-application-while-phone-boots-up