I'm developing a launcher application, I just added a broadcast receiver I will use to update the app list. I initially tried to receive ACTION_PACKAGE_ADDED
and ACTION_PACKAGE_REMOVED
as they seemed enought for the job, however none where fired so I added all other package-related actions I deemed useful and tried to register for them both in the activity:
val intentFilter = IntentFilter()
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED)
intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED)
intentFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED)
intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL)
intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED)
val rec = AppsInstallationsReceiver()
registerReceiver(rec, intentFilter)
and manifest:
<receiver android:name=".core.installed_apps.AppsInstallationsReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
The receiver itself is nothing special:
class AppsInstallationsReceiver : BroadcastReceiver() {
override fun onReceive(p0: Context?, p1: Intent?) {
//TODO
}
}
turns out I only receive PACKAGE_FULLY_REMOVED
and only if it's registered in the manifest.
Now this is good enought, but I need a way to know when new apps are installed. Since this is a launcher app this feature is critical. Why am I not receiving anything? the activity of course still exists the background since it is used as launcher.
question from:
https://stackoverflow.com/questions/65952773/android-package-related-intents-not-fired 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…