Regarding android.intent.action.PACKAGE_ADDED,android.intent.action.PACKAGE_REMOVED

2,410 views
Skip to first unread message

ashiq sayyad

unread,
Mar 9, 2012, 8:02:48 AM3/9/12
to Android Developers, android-...@googlegroups.com
Hi,

Hope all doing well..

I have a broadcast receiver in my app to check if my app is installed
or deleted. So I have added following intent filter in the manifest..

<receiver android:name="com.packagereceiver.PackageReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action
android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"
/>
</intent-filter>
</receiver>
But the problem is my receiver gets notification for any apps
installed or deleted on phone..

Is there any way to get notification only for certain predefined
packages(apps ) installation or uninstallation..

Thanks & Regards,
Ashiq sayyad

Tez

unread,
Mar 12, 2012, 8:11:12 AM3/12/12
to android-platform
you can filter in code using the intent extras.
Read the docs!

-Earlence

Dianne Hackborn

unread,
Mar 12, 2012, 8:50:02 PM3/12/12
to android-...@googlegroups.com
(1) Drop the one for PACKAGE_REMOVED.  You won't get that for your app.
(2) API demos has an example for receiving a broadcast when your app is updated.  Look for MY_PACKAGE_REPLACED here: http://developer.android.com/resources/samples/ApiDemos/AndroidManifest.html

That said, MY_PACKAGE_REPLACED was added in Android 3.1 as described here: http://developer.android.com/reference/android/content/Intent.html#ACTION_MY_PACKAGE_REPLACED

If you want to do this on older versions of the platform, you will need to watch PACKAGE_ADDED.  Unfortunately there isn't a way to specify in your intent filter that you will only be launched for PACKAGE_ADDED of your app, so I would really encourage you to stay away from it.  (It is not a good thing to have tons of apps launching every time some arbitrary apps is installed or updated.)

So my question to you -- why do you think you need to do this?  You can't use this to be launched either when you are installed or uninstalled.  You can only do this to be launched when your app is updated, and in most cases you can just as well check your app version against a value you last stored in your persistent settings to determine if this happened and do whatever you are wanting to do.


--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Reply all
Reply to author
Forward
0 new messages