在清单中注册的广播接收器未在Android Oreo中调用

Rag*_*ini 8 android broadcastreceiver android-8.0-oreo

我已注册以下receiver内容未在Android Oreo中调用,但适用于较低版本的设备.

<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>  
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激?

Com*_*are 8

通常,您不能Intent在Android 8.0+上使用隐式(例如,只有动作字符串的一个)进行广播.

<receiver>没有出口.这表明三件事之一:

  1. 你正在使用它PendingIntent,例如a Notification.如果是这样,摆脱<intent-filter>并使用explicit Intent(new Intent(this, ConsultReceiver.class))作为创建PendingIntent指向此接收器的一部分.

  2. 您正在将此作为应用程序中多个应用程序进程之间的某些IPC的一部分.在这种情况下,也使用显式Intent.

  3. 您只是在应用程序的一个过程中使用此接收器.在这种情况下,摆脱<receiver>并使用其他东西(LocalBroadcastManager,事件总线,RxJava LiveData等).


Nir*_*pat 5

如果您的应用面向 API 级别 26 或更高级别,则不能使用清单来声明隐式广播(不专门针对您的应用的广播)的接收器,除了一些不受该限制的隐式广播。在大多数情况下,您可以改用计划作业。