Autostart application while phone boots up

扶醉桌前 提交于 2019-11-27 16:52:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!