atom feed9 messages in com.googlegroups.android-developersRe: How can I get Actions: PACKAGE_RE...
FromSent OnAttachments
JoeJan 21, 2008 7:25 pm 
hackbodJan 23, 2008 1:55 pm 
JoeJan 23, 2008 5:44 pm 
jcku...@gmail.comFeb 21, 2008 11:56 pm 
hackbodFeb 22, 2008 12:04 am 
jcku...@gmail.comFeb 22, 2008 2:03 am 
viktorFeb 27, 2008 3:43 pm 
hackbodFeb 27, 2008 3:51 pm 
viktorFeb 27, 2008 5:12 pm 
Subject:Re: How can I get Actions: PACKAGE_REMOVED and PACKAGE_ADDED
From:viktor (vikt@yahoo.com)
Date:Feb 27, 2008 5:12:56 pm
List:com.googlegroups.android-developers

Thank you, now it works.

The broadcast will probably be sent to the package that got installed, but uh... nice that you mention that, I might change that. ;)

Please do not change that! This is a useful feature. Imagine an application that requires a service constantly running. For example an application that monitors phone location and notifies the user when he approaches certain geographical point. The application uses the BOOT_COMPLETED broadcast to start the service when the phone boots up. The application also must start the service when the new version is installed because deleting the apk file kills the service. To do so, the application will listen for PACKAGE_INSTALL, PACKAGE_ADDED and PACKAGE_CHANGED broadcasts and start the service if the intent data matches the application package name. If you prevent these broadcasts to the package that got installed, please provide an application with a mechanism to run some code after it gets installed on the phone.

Just to make this topic complete, here is the manifest that worked for me:

<receiver android:name="PackageAddedReceiver"> <intent-filter> <action android:name="android.intent.action.PACKAGE_INSTALL" /> <action android:name="android.intent.action.PACKAGE_ADDED" /> <action android:name="android.intent.action.PACKAGE_CHANGED" /

<category android:name="android.intent.category.DEFAULT" /> <data android:scheme="package" /> </intent-filter> </receiver>

On Feb 27, 6:52 pm, hackbod <hack@gmail.com> wrote:

Yes, PACKAGE_ADDED is broadcast.  You need to also say you handle the "package" scheme (the data is a Uri of the form "package:<package- name>").

The broadcast will probably be sent to the package that got installed, but uh...  nice that you mention that, I might change that. ;)

Fwiw, this is the code in the home screen that registers a receiver at runtime:

        filter = new IntentFilter(Intent.PACKAGE_ADDED_ACTION);         filter.addAction(Intent.PACKAGE_REMOVED_ACTION);         filter.addAction(Intent.PACKAGE_CHANGED_ACTION);         filter.addDataScheme("package");         registerReceiver(mApplicationsReceiver, filter);

On Feb 27, 3:43 pm, viktor <vikt@yahoo.com> wrote:

What event(s) in the system triggers the PACKAGE_ADDED intent? Is running the command "adb install mypackage.apk" sufficient? I tried it and my registered intent receiver does not receive the intent. So I need to know if my manifest is wrong or the intent does not get broadcasted.

Also, is the intent broadcasted to the package that has just been installed?

Manifest: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.obd2.test">     <application android:icon="@drawable/icon">         <activity android:name="Test" android:label="@string/ app_name">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                 <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>     </application>     <receiver android:name="PackageAddedReceiver">         <intent-filter>              <action android:name="android.intent.action.PACKAGE_ADDED" />         </intent-filter>     </receiver> </manifest>

Receiver: public class PackageAddedReceiver extends IntentReceiver {         @Override         public void onReceiveIntent(Context conext, Intent intent) {                 android.util.Log.i("test", intent.getData().toString());         }

}

On Jan 23, 4:56 pm, hackbod <hack@gmail.com> wrote:

To receive these actions, you need to handle the "package:" scheme. The Intent being broadcast sends the package name as "package:<name>".  So you should write something like this:

            <intent-filter>                 <action android:value="android.intent.action.PACKAGE_ADDED" />                 <action android:value="android.intent.action.PACKAGE_REMOVED" />                 <scheme android:value="package" />             </intent-filter>

The two permissions you mentioned are not relevant -- the BROADCAST_PACKAGE_REMOVED permission is to allow you to -broadcast- that intent (which you aren't needing to do), and INSTALL_PACKAGES is to allow you to physically install a package on the device.

On Jan 21, 7:25 pm, Joe <penc@hotmail.com> wrote:

I want to get the Installing and removing package name, I found that there are two broadcast Actions: PACKAGE_REMOVED and PACKAGE_ADDED can help doing that. And I found the permission about packages is only "android.permission.BROADCAST_PACKAGE_REMOVED" and "android.permission.INSTALL_PACKAGES", but they are not associated with the two actions. So I cannot process these two actions. Following is my test code, can anyone tell me what's wrong with my codes or how can I get the actions. .....     <uses-permission id="android.permission.BROADCAST_PACKAGE_REMOVED" />     <uses-permission id="android.permission.INSTALL_PACKAGES" /> ....         <receiver class=".PackageProcess">             <intent-filter>                 <action android:value="android.provider.Telephony.SMS_RECEIVED" />                 <action android:value="android.intent.action.PACKAGE_ADDED"    />                 <action android:value="android.intent.action.PACKAGE_REMOVED" />             </intent-filter>         </receiver> ....      public void onReceiveIntent(Context context, Intent intent) {           /* As we want to display a Notification, we the NotificationManager */

          Log.i("recevie the message is ", intent.getAction());  //can not print this line ......

}- Hide quoted text -

- Show quoted text -- Hide quoted text -