Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为操作动态注册BroadcastReceiver\u BOOT\u已完成不工作?_Android_Broadcastreceiver_Android Service_Boot_Android Broadcast - Fatal编程技术网

Android 为操作动态注册BroadcastReceiver\u BOOT\u已完成不工作?

Android 为操作动态注册BroadcastReceiver\u BOOT\u已完成不工作?,android,broadcastreceiver,android-service,boot,android-broadcast,Android,Broadcastreceiver,Android Service,Boot,Android Broadcast,重新启动或启动手机后,我的广播接收器未重新启动服务 我的接收器类别代码: public class MyReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Intent serviceIntent = new Intent(context, MyService.class); context.startService

重新启动或启动手机后,我的广播接收器未重新启动服务

我的接收器类别代码:

public class MyReceiver extends BroadcastReceiver
{
    public void onReceive(Context context, Intent intent)
    {
        Intent serviceIntent = new Intent(context, MyService.class);
        context.startService(serviceIntent);
    }
}
在onStartCommand()方法中注册接收器的我的服务类代码:

我无法在我的Android清单中注册接收器,因为我只能在我的服务类中列出的某些条件下注册此广播接收器。我启用了

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


但是在我的Android清单文件中

这行不通。获得操作\u启动\u完成广播的唯一方法是通过清单注册的广播接收器。

重新启动后,您如何在第一个位置启动服务?谢谢,是的,我发现了同样的问题,因为我刚刚找到了解决方案。使用PackageManager类,我可以启用和禁用接收方,即使它已在清单中注册,因此它实际上与在代码中动态注册接收方相同(至少对于我的程序)。无论如何谢谢你的帮助。
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>