在清单中注册的广播接收器未在 Android Oreo 中调用 [英] Broadcast receiver registered in manifest not getting called in Android Oreo
问题描述
我已经注册了以下 receiver
,它不会在 Android Oreo 中被调用,但可以在较低版本的设备上运行.
I have registered following receiver
which is not getting called in Android Oreo but works on lower version devices.
<receiver
android:name=".common.receiver.ConsultReceiver"
android:exported="false">
<intent-filter>
<action android:name="APP_STARTED" />
<action android:name="APP_STARTED_FROM_ORGANIC" />
</intent-filter>
</receiver>
任何帮助将不胜感激?
推荐答案
一般来说,您不能在 Android 8.0+ 上使用隐式 Intent
(例如,只有一个操作字符串)进行广播.
In general, you cannot use an implicit Intent
(e.g., one with just an action string) for a broadcast on Android 8.0+.
您的
未导出.这表明以下三件事之一:
Your <receiver>
is not exported. This suggests one of three things:
您将其与
PendingIntent
一起使用,例如用于Notification
.如果是这样,去掉
并使用显式Intent
(new Intent(this, ConsultReceiver.class)
)作为创建指向此接收器的PendingIntent
的一部分.
You are using this with a
PendingIntent
, such as for aNotification
. If so, get rid of the<intent-filter>
and use an explicitIntent
(new Intent(this, ConsultReceiver.class)
) as part of creating yourPendingIntent
that points to this receiver.
您将其用作应用程序中多个应用程序进程之间某些 IPC 的一部分.在这种情况下,还要使用显式 Intent
.
You are using this as part of some IPC between multiple app processes in your app. In that case, also use an explicit Intent
.
您纯粹是在应用内的一个进程中使用此接收器.在这种情况下,去掉
并使用其他东西(LocalBroadcastManager
、事件总线、RxJava、LiveData
等.).
You are using this receiver purely within one process within your app. In that case, get rid of the <receiver>
and use something else (LocalBroadcastManager
, an event bus, RxJava, LiveData
, etc.).
这篇关于在清单中注册的广播接收器未在 Android Oreo 中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!