Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.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
Java 在8.1.0上接收广播_Java_Android - Fatal编程技术网

Java 在8.1.0上接收广播

Java 在8.1.0上接收广播,java,android,Java,Android,我有一个在Android 8.0API26物理设备和一个8.0模拟器上工作的广播。它不适用于Android 8.1.0模拟器或物理设备 我也试着注册了接收器,但仍然没有工作 Intent intent=new Intent(this, MainActivity.class); intent.setAction("com.my.receiver"); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); sendBroadcast(inten

我有一个在Android 8.0API26物理设备和一个8.0模拟器上工作的广播。它不适用于Android 8.1.0模拟器或物理设备

我也试着注册了接收器,但仍然没有工作

Intent intent=new Intent(this, MainActivity.class);
intent.setAction("com.my.receiver");
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(intent);
xml

这里指定的Java类是MainActivity

这里指定的Java类是.Helpers.MyReceiver


这些不一样。此接收器不会在任何版本的Android上接收此广播,更不用说Android 8.1了。

在api 27以下的任何版本上都能正常工作。我在物理Android 8.0 API 26设备和8.0仿真器上有一个工作广播。@EdwardDiGirolamo:在API 27以下的任何设备上都能正常工作-您问题中的代码没有。也许您运行的代码与问题中的代码不同。或者,您可能正在将真正的广播发送到其他地方,因为对于BroadcastReceiver子类来说,MainActivity是一个非常奇怪的名称。
<receiver
    android:name=".Helpers.MyReceiver"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="com.my.receiver"/>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
    </intent-filter>
</receiver>
Intent intent=new Intent(this, MainActivity.class);
android:name=".Helpers.MyReceiver"