不是的android接受意向ACTION_PACKAGE_REMOVED在去除包装 [英] android not receiving Intent ACTION_PACKAGE_REMOVED in the removed package

查看:785
本文介绍了不是的android接受意向ACTION_PACKAGE_REMOVED在去除包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序被删除,我想也删除该应用程序已在SD卡上创建的文件,因为它们会消耗许多兆字节,并且只使用到我的应用程序。

看来接收包装中取出的意图是要做到这一点的地方。 然而,我的广播接收器不会被调用 - 它似乎除去包装意图被发送之前已被删除

在code是:

公共类UninstallReceiver扩展的BroadcastReceiver {
 @覆盖
 公共无效的onReceive(上下文的背景下,意图意图){
  串动= intent.getAction();
  Log.i(U,动作+动作);
  等等
 }
}

和,在清单:

 <应用机器人:可调试=真
  机器人:图标=@可绘制/图标
  机器人:标签=@字符串/ APP_NAME>

  <接收器的Andr​​oid版本:NAME =com.boom.UninstallReceiver>
   <意图过滤器>
        <作用机器人:名称=android.intent.action.PACKAGE_REMOVED/>
     <数据机器人:计划=包/>
   < /意图过滤器>
  < /接收器>

解决方案

的<一个href="http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_REMOVED">documentation说:

  

正在安装的软件包没有收到此意向。

在这种情况下,装是一个拼写错误 - 它确实应该是删除。因此,您无法收到该广播。

Android 2.2的加入 getExternalFilesDir(),这将指向外部存储的机器人会自动清理,当你的应用程序卸载的地方。然而,这仅仅是对机器人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 installed does not receive this Intent.

In this case, "installed" is a typo -- it really should be "removed". Hence, you cannot receive this broadcast.

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接受意向ACTION_PACKAGE_REMOVED在去除包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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