android 在已删除的包中没有收到 Intent ACTION_PACKAGE_REMOVED [英] android not receiving Intent ACTION_PACKAGE_REMOVED in the removed package

查看:36
本文介绍了android 在已删除的包中没有收到 Intent ACTION_PACKAGE_REMOVED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的 android 应用被删除时,我还想删除该应用在 SD 卡上创建的文件,因为这些文件会消耗很多兆字节并且只对我的应用有用.

似乎接收 PACKAGE REMOVED 意图将是执行此操作的地方.但是,我的广播接收器从未被调用——它似乎在发送 PACKAGE REMOVED 意图之前已被删除

代码是:

<上一页>公共类 UninstallReceiver 扩展 BroadcastReceiver {@覆盖公共无效 onReceive(上下文上下文,意图意图){字符串动作=意图.getAction();Log.i("U", "动作" + 动作);等等.}}

并且,在清单中:

<上一页><应用程序 android:debuggable="true"android:icon="@drawable/icon"android:label="@string/app_name"><receiver android:name="com.boom.UninstallReceiver"><意图过滤器></意图过滤器></接收者>

解决方案

文档 说:

<块引用>

被移除的包没有收到这个 Intent.

Android 2.2 添加了 getExternalFilesDir(),它将指向外部存储上的一个位置,Android 将在您的应用程序卸载时自动清理该位置.但是,这仅适用于 Android 2.2,并且有迹象表明它目前运行得不是特别好.但是,在 2011 年要牢记这一点.

除此之外,您真正能做的就是在某处为用户提供一个菜单选项来进行清理,并希望用户在卸载您之前使用它.

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>

解决方案

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.

这篇关于android 在已删除的包中没有收到 Intent ACTION_PACKAGE_REMOVED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆