在清单中注册的广播接收器未在Android Oreo中被调用 [英] Broadcast receiver registered in manifest not getting called in Android Oreo

查看:70
本文介绍了在清单中注册的广播接收器未在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>  

有什么帮助吗?

推荐答案

通常,

In general, you cannot use an implicit Intent (e.g., one with just an action string) for a broadcast on Android 8.0+.

您的<receiver>未导出.这表明三件事之一:

Your <receiver> is not exported. This suggests one of three things:

  1. 您正在将其与PendingIntent一起使用,例如用于Notification.如果是这样,请摆脱<intent-filter>并使用显式的Intent(new Intent(this, ConsultReceiver.class))作为创建指向此接收器的PendingIntent的一部分.

  1. You are using this with a PendingIntent, such as for a Notification. If so, get rid of the <intent-filter> and use an explicit Intent (new Intent(this, ConsultReceiver.class)) as part of creating your PendingIntent 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.

您仅在应用程序的一个过程中使用此接收器.在这种情况下,请摆脱<receiver>并使用其他东西(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆