Autostart application while phone boots up

我怕爱的太早我们不能终老 提交于 2019-11-29 02:37:27

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