Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

android not receiving Intent ACTION_PACKAGE_REMOVED in the removed package

When my android app is removed, I would like to also remove files the app has created on the SD card, as these can consume many megabytes and are only of use to my app.

It seems that receiving the PACKAGE REMOVED intent would be the place to do this. However, my broadcast receiver is never called--it seems to have been deleted before the PACKAGE REMOVED intent is sent

The code is:

public class UninstallReceiver extends BroadcastReceiver {
 @Override
 public void onReceive(Context context, Intent intent) {
  String action= intent.getAction();
  Log.i("U", "ACTION " + action);
  etc.
 }
}

and, in the manifest:

 <application android:debuggable="true"
  android:icon="@drawable/icon"
  android:label="@string/app_name">

  <receiver android:name ="com.boom.UninstallReceiver">
   <intent-filter>
        <action android:name="android.intent.action.PACKAGE_REMOVED"/> 
     <data android:scheme="package" />
   </intent-filter>
  </receiver>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The documentation says:

The package that is being removed does not receive this Intent.

Android 2.2 added getExternalFilesDir(), which will point to a place on the external storage that Android will automatically clean up when your application is uninstalled. However, that is only for Android 2.2, and there are indications that it does not work particularly well at the moment. However, it is something to keep in mind for 2011.

Beyond that, all you can really do is offer a menu choice somewhere for the user to do the cleanup, and hope users use it before uninstalling you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...