[英]Android autostart application
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?
我必须在AndroidManifest中包含哪些权限?
Thanks 谢谢
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): 在您的<application>元素中(确保对BroadcastReceiver使用完全限定的[或相对]类名):
<receiver android:name="com.example.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
In MyBroadcastReceiver.java: 在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 以获得更多帮助:: http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/ http://blog.gregfiumara.com/archives/82 http://androidgps.blogspot.com/ 2008/09 /启动功能的Android服务,在引导,为time.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.