我在一个物理的Android8.0 (API 26)设备上有一个工作广播,还有一个8.0模拟器。它不适用于Android8.1.0模拟器或物理设备。
我也试着注册接收器,但仍然不起作用。
Intent intent=new Intent(this, MainActivity.class);
intent.setAction("com.my.receiver");
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(intent);xml
<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>发布于 2018-01-19 20:45:56
Intent intent=new Intent(this, MainActivity.class);您在这里指定的Java类是MainActivity。
android:name=".Helpers.MyReceiver"您在这里指定的Java类是.Helpers.MyReceiver。
这些是不一样的。这个接收器不会在任何版本的Android上接收到这个广播,更不用说Android8.1了。
https://stackoverflow.com/questions/48349232
复制相似问题