Reputation: 63
I need to get a notification once the app is intalled on android device. Based on the status that app is installed or not then i need to update something. Please help me on this.
Thanks KIRAN
Upvotes: 2
Views: 2731
Reputation: 789
I recently come across this problem. Here is how it's working for me. I am targeting API level 30. I have created a broadcast receiver that notifies me when an app is installed or uninstalled on the device.
Following is my receiver tag inside the Application tag in AndroidManifest.xml. I didn't find PACKAGE_ADDED action working for me.
<receiver android:name="com.vikasmane.appdatasdk.PackageChangeReceiver" android:exported="true">
<intent-filter android:priority="999">
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
Queries tag required to receive PACKAGE_CHANGED. This can be added under the manifest tag
<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
</intent>
</queries>
The PackageChangeReceiver receives PACKAGE_FULLY_REMOVED/PACKAGE_CHANGED. The package name can be retrieved using
val packageName = intent?.data?.encodedSchemeSpecificPart
Here is my Broadcast receiver
class PackageChangeReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
// fetching package names from extras
val packageName = intent?.data?.encodedSchemeSpecificPart
when (intent?.action) {
Intent.ACTION_PACKAGE_FULLY_REMOVED -> Toast.makeText(
context,
"${packageName.toString()} uninstalled",
Toast.LENGTH_SHORT
).show()
Intent.ACTION_PACKAGE_CHANGED -> Toast.makeText(
context,
"${packageName.toString()} installed",
Toast.LENGTH_SHORT
).show()
}
}
You can find this implementation in my repo https://github.com/vikasvmane/Launcher for reference.
Upvotes: 0
Reputation: 3910
I believe the intent "android.intent.action.PACKAGE_ADDED" is broadcasted when a new app is installed.
Upvotes: 3