[英]Android autostart application
如何在设备启动时自动启动应用程序的服务(可以启用/禁用此功能)? 我必须在AndroidManifest中包含哪些权限?
谢谢
此权限被使用
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
在您的<application>元素中(确保对BroadcastReceiver使用完全限定的[或相对]类名):
<receiver android:name="com.example.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
在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);
}
}
以获得更多帮助:: 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.