尝试在Android上启动时启动服务
当设备在android上启动时,我一直在尝试启动服务,但无法正常工作。我已经看了许多在线链接,但是这些代码都不起作用。我忘记了什么吗?
AndroidManifest.xml<receiver
    android:name=".StartServiceAtBootReceiver"
    android:enabled="true"
    android:exported="false"
    android:label="StartServiceAtBootReceiver" >
    <intent-filter>
        <action android:name="android.intent.action._BOOT_COMPLETED" />
    </intent-filter>
</receiver>
<service
    android:name="com.test.RunService"
    android:enabled="true" />
广播接收器
public void onReceive(Context context, Intent intent) {    if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
        Intent serviceLauncher = new Intent(context, RunService.class);
        context.startService(serviceLauncher);
        Log.v("TEST", "Service loaded at start");
    }
}
回答:
作为附加信息:BOOT_COMPLETE在挂载外部存储之前发送到应用程序。因此,如果将应用程序安装到外部存储,它将不会收到BOOT_COMPLETE广播消息。
以上是 尝试在Android上启动时启动服务 的全部内容, 来源链接: utcz.com/qa/399182.html
