Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

broadcastreceiver - Broadcast receiver registered in manifest not getting called in 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>  

Any help would be appreciated?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  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.

  2. You are using this as part of some IPC between multiple app processes in your app. In that case, also use an explicit Intent.

  3. 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.).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...