Status Update
Comments
su...@google.com <su...@google.com> #2
Thank you for reporting this issue. For us to further investigate this issue, please provide the following additional information:
Please mention the steps to be followed for reproducing the issue with the given sample apk.
Android full bug report capturing
After reproducing the issue, press the volume up, volume down, and power button simultaneously. This will capture a bug report on your device in the “bug reports” directory.
Alternate method
Navigate to “Developer options”, ensure “USB debugging” is enabled, then enable “Bug report shortcut”. Capture bug report by holding the power button and selecting the “Take bug report” option.
Screen record of the issue, for clarity
Please capture screen record or video of the issue using the following steps:
adb shell screenrecord /sdcard/video.mp4
Subsequently use following command to pull the recorded file:
adb pull /sdcard/video.mp4\
Note: Please upload the files to google drive and share the folder to
ap...@gmail.com <ap...@gmail.com> #3
Error: The intent action com.example.action (used to send a broadcast) matches the intent filter of a non-exported receiver, registered via a call to Context.registerReceiver, or similar. If you are trying to invoke this specific receiver via the action then you should use Intent.setPackage(<APPLICATION_ID>). [UnsafeImplicitIntentLaunch]
Button(onClick = { context.sendBroadcast(Intent("com.example.action")) }) {}
I wasn't aware that the explicit intent requirements from API 34 applied to broadcasts as well. I do think it would be beneficial to display this error when building the app for development, not just during the build task to produce an APK. Either way, the issue isn't an issue after all.
zi...@gmail.com <zi...@gmail.com> #4
Thanks.
ke...@gmail.com <ke...@gmail.com> #5
* Dynamically registered receiver with RECEIVER_EXPORTED flag: Can get broadcast with custom action sent from the same app using `Context#sendBroadcast()` API.
* Dynamically registered receiver with RECEIVER_NOT_EXPORTED flag: Cannot get broadcast with custom action sent from the same app using `Context#sendBroadcast()` API.
su...@google.com <su...@google.com>
at...@google.com <at...@google.com>
at...@google.com <at...@google.com> #6
Thank you for reporting this issue. We have shared this with our product and engineering team and will update this issue with more information as it becomes available.
at...@google.com <at...@google.com> #7
Our engineering team responded :
It is indeed related to the changes applied for Safer Implicit Intents, this is the intended behaviour.
To fix this issue, the developer will need to make the intent explicit (either explicit by package or explicit by component), the following change will fix it:
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier, context: Context) {
Button(onClick = { context.sendBroadcast(Intent("com.example.action")) }) {}
}
should become something like:
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier, context: Context) {
val intent = Intent("com.example.action")
intent.setPackage(context.getPackageName())
Button(onClick = { context.sendBroadcast(intent) }) {}
}
at...@google.com <at...@google.com> #8
ke...@gmail.com <ke...@gmail.com> #9
ch...@google.com <ch...@google.com> #10
We’ll be closing this issue due to not having enough actionable information. If you continue to have this issue, please open a new issue and add the relevant information along with a reference link to the earlier issue.
bm...@salesforce.com <bm...@salesforce.com> #11
dh...@ajmerainfotech.com <dh...@ajmerainfotech.com> #12
dh...@ajmerainfotech.com <dh...@ajmerainfotech.com> #13
I have registered the receiver with a custom action.
Sending like this:
Intent intent = new Intent("com.gt-broadcast-refresh");
requireActivity().sendBroadcast(intent);
Receiving like this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
requireActivity().registerReceiver(refreshUIReceiver, new IntentFilter("com.gt-broadcast-refresh"), Context.RECEIVER_NOT_EXPORTED);
} else {
requireActivity().registerReceiver(refreshUIReceiver, new IntentFilter("com.gt-broadcast-refresh"));
}
It will work in the emulator with an Android 14 device, but it will not work on a real device, such as the Google Pixel 8 Pro, because it will not listen to the action. I have configured the registration based on the Google documentation for Android 14.
should I need to add any extra flag or permission while sending the custom action?
dh...@ajmerainfotech.com <dh...@ajmerainfotech.com> #14
All, I found the solution for all requireActivity().registerReceiver()
calls. They will only listen for the action if the action is sent with the package name of the application. So whenever we send a broadcast, we should also set the package with the intent using intent.setPackage(getPackageName())
. Then, the registered receiver will be able to listen for the action.
Reference link:
m....@gmail.com <m....@gmail.com> #15
Unbelievable, 9 months later this is still not in the docs.
Description
I tested with the RECEIVER_EXPORTED flag, and that works, and I also changed the target and compile SDKs to 33 and left the RECEIVER_NOT_EXPORTED flag, and that also works.
I put together a small test app and was able to reproduce the issue, and I attached the project. The only changes I made to the template created by Android Studio was update the androidx core-ktx version to 1.10.1, set the target and compile SDK to 34, the minimum SDK to 28, and put together a small broadcast example with the activity template. Here is the MainActivity.kt:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
TestAppTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
Greeting("Android", context = this@MainActivity)
}
}
}
ContextCompat.registerReceiver(this, object : BroadcastReceiver() {
override fun onReceive(p0: Context?, p1: Intent?) {
Toast.makeText(this@MainActivity, "Test", Toast.LENGTH_LONG).show()
}
}, IntentFilter("com.example.action"), ContextCompat.RECEIVER_EXPORTED)
}
}
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier, context: Context) {
Button(onClick = { context.sendBroadcast(Intent("com.example.action")) }) {}
}