Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PACKAGE_REMOVED & then PACKAGE_ADDED are fired along with PACKAGE_REPLACED Intent Action

All I am trying to do is update my list on each Install & Uninstall but not on Package Replace .So the main problem is that Install & Uninstall intents are launched on each Replace action.

So For this I have implemented a BroadcastReciever as below

<receiver android:name =".IntentReceiverTest.AppReciever">
  <intent-filter>
         <action android:name="android.intent.action.PACKAGE_REMOVED"/>
         <action android:name="android.intent.action.PACKAGE_REPLACED"/>
         <action android:name="android.intent.action.PACKAGE_ADDED"/>
         <data android:scheme="package"/> 
  </intent-filter>
</receiver> 

On each Replace I get 3 broadcasts with actions

  • First with PACKAGE_REMOVED which fires AppReciever
  • then after PACKAGE_ADDED which again fires AppReciever
  • And then after few seconds PACKAGE_REPLACED which again fires AppReciever

So please suggest any better way to catch only Replace Action

Or

a way to stop previously launched Services due to PACKAGE_REMOVED and PACKAGE_ADDED action.

like image 796
100rabh Avatar asked Mar 07 '11 08:03

100rabh


People also ask

How do you use intent?

To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.

What is intent action?

An Intent is a messaging object you can use to request an action from another app component. Although intents facilitate communication between components in several ways, there are three fundamental use cases: Starting an activity. An Activity represents a single screen in an app.

What is intent Flag_activity_new_task?

FLAG_ACTIVITY_NEW_TASK is equivalent to launchMode=singleTask and in there I read. However, if an instance of the activity already exists in a separate task, the system routes the intent to the existing instance through a call to its onNewIntent() method, rather than creating a new instance.

What is intent class?

An intent is to perform an action on the screen. It is mostly used to start activity, send broadcast receiver,start services and send message between two activities. There are two intents available in android as Implicit Intents and Explicit Intents. Here is a sample example to start new activity with old activity.


1 Answers

Just check intent.getBooleanExtra(Intent.EXTRA_REPLACING, false):

if (!intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED) &&     intent.getBooleanExtra(Intent.EXTRA_REPLACING, false))     return; 
like image 85
ChrOnOs Avatar answered Sep 28 '22 08:09

ChrOnOs