Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 13 RECEIVER_EXPORTED's explanation is correct?

This is what google explains about RECEIVER_EXPORTED, RECEIVER_NOT_EXPORTED:

Choose whether the broadcast receiver should be exported and visible to other apps on the device. If this receiver is listening for broadcasts sent from the system or from other apps—even other apps that you own—use the RECEIVER_EXPORTED flag. If instead this receiver is listening only for broadcasts sent by your app, use the RECEIVER_NOT_EXPORTED flag.

When I want to use broadcasts sent from the system Google says I need to use RECEIVER_EXPORTED but when I tested with "android.intent.action.AIRPLANE_MODE" and "RECEIVER_NOT_EXPORTED". I received a broadcast event. Can anyone explain that sentence?

like image 503
skytree Avatar asked Dec 11 '25 20:12

skytree


1 Answers

I'm getting this error:

Must be one or more of: Context.RECEIVER_VISIBLE_TO_INSTANT_APPS, android.content.Context.RECEIVER_EXPORTED, android.content.Context.RECEIVER_NOT_EXPORTED

even though I have it set to RECEIVER_NOT_EXPORTED and I get the same error if I set it to RECEIVER_EXPORTED. It's as if I'm not satisfying the @RegisterReceiverFlags interface.


Must be one or more of: Context.RECEIVER_VISIBLE_TO_INSTANT_APPS, android.content.Context.RECEIVER_EXPORTED, android.content.Context.RECEIVER_NOT_EXPORTED

It suggests RECEIVER_NOT_EXPORTED as preferred initially, but when it shows this error, it offers that I change it to RECEIVER_VISIBLE_TO_INSTANT_APPS. If I set it to that, it takes away the error but then highlights it in yellow and suggests that I add one of the other two… which still error if I include multiple flags.

EDIT: Okay, I fixed this by using ContextCompat.registerReceiver() instead of regular registerReceiver() which also requires using ContextCompat.RECEIVER_NOT_EXPORTED instead of Context.RECEIVER_NOT_EXPORTED.

like image 156
Literate Corvette Avatar answered Dec 13 '25 09:12

Literate Corvette