Android autostart application

久未见 提交于 2019-12-18 18:31:18

问题


How can I autostart my application's service at device boot (with the possibility of enabling/disabling this feature)? What permissions do I have to include in AndroidManifest?

Thanks


回答1:


this permission are use

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

In your <application> element (be sure to use a fully-qualified [or relative] class name for your BroadcastReceiver):

<receiver android:name="com.example.MyBroadcastReceiver">  
    <intent-filter>  
        <action android:name="android.intent.action.BOOT_COMPLETED" />  
    </intent-filter>  
</receiver>

In MyBroadcastReceiver.java:

package com.example;

public class MyBroadcastreceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent startServiceIntent = new Intent(context, MyService.class);
        context.startService(startServiceIntent);
    }
}



for more help :: http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/ http://blog.gregfiumara.com/archives/82 http://androidgps.blogspot.com/2008/09/starting-android-service-at-boot-time.html



来源:https://stackoverflow.com/questions/7317939/android-autostart-application

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