I have created a broadcast receiver and registered it, but i am not able to receive the Intent.ACTION_PACKAGE_ADDED events.
val intentFilter = IntentFilter().apply {
addAction(Intent.ACTION_PACKAGE_ADDED)
addAction(Intent.ACTION_PACKAGE_REMOVED)
addDataScheme("package")
}
intentFilter.priority = 999
val rec = IntentReceiver()
registerReceiver(rec, intentFilter)
This is my BroadcastReceiver class
class IntentReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
Toast.makeText(context, "TEST TOAST", Toast.LENGTH_LONG).show()
val builder =
NotificationCompat.Builder(context!!, "worker_channel")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("App is installed")
.setPriority(NotificationCompat.PRIORITY_HIGH)
val notificationManager: NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(4, builder.build())
}}
I am not getting any events, however the same broadcast receiver works for intents like:
Intent.ACTION_PACKAGE_REMOVED
Intent.ACTION_AIRPLANE_MODE_CHANGED
and also i am getting logs for PACKAGE_ADDED Events in Logcat as
W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.socialnmobile.dictapps.notepad.color.note flg=0x4000010 (has extras) } to com.google.android.gms/.gass.chimera.PackageChangeBroadcastReceiver
I have tested on android 11 and 12 every other intents are working fine except Intent.ACTION_PACKAGE_ADDED, am i missing anything or doing something wrong?
Issue is resolved, i had to add query all packages permission for android versions after 10, don't know why it isn't mentioned anywhere in the docs.
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES" />