android 在已删除的包中没有收到 Intent ACTION_PACKAGE_REMOVED

android not receiving Intent ACTION_PACKAGE_REMOVED in the removed package(android 在已删除的包中没有收到 Intent ACTION_PACKAGE_REMOVED)
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)