在android中执行卸载任务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3013823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:18:15  来源:igfitidea点击:

Perform a task on uninstall in android

androiduninstall

提问by dhaiwat

I have developed an Android app. Now I want to perform a few operations (i. e. - Reset the settings etc.. ) at the moment the app gets uninstalled from the phone.

我开发了一个Android应用程序。现在我想在应用程序从手机上卸载时执行一些操作(即 - 重置设置等)。

Is it possible to reigster a listener or a function that is called at the moment the app is removed?

是否可以重新注册在删除应用程序时调用的侦听器或函数?

采纳答案by Janusz

Sadly android at the moment does not give you a possibility to perform code at the moment your app is uninstalled.

遗憾的是,目前 android 无法让您在卸载应用程序时执行代码。

All the settings that are set via the SharedPreferences are deleted together with everything in the Application Data an Cache folder.

通过 SharedPreferences 设置的所有设置都将与 Application Data an Cache 文件夹中的所有内容一起删除。

The only thing that will persist is the data that is written to the SD-Card and any changes to phone settings that are made. I don't know what happens to data that is synchronized to the contacts through your app.

唯一会保留的是写入 SD 卡的数据以及对手机设置所做的任何更改。我不知道通过您的应用同步到联系人的数据会发生什么。

回答by CommonsWare

You cannot get control when your application is uninstalled -- sorry!

当您的应用程序被卸载时,您无法控制——抱歉!

回答by jasonhudgins

Since API level 8 you may use Context.getExternalFilesDir(). In theory any data placed here will be removed when the application is uninstalled.

从 API 级别 8 开始,您可以使用 Context.getExternalFilesDir()。理论上,当卸载应用程序时,放置在这里的任何数据都将被删除。

http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)

http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)

回答by user3454856

When user uninstall android application in his mobile the PACKAGE_REMOVED receiver will call. You can get uninstalled app package name use intent,getDataString()

当用户在他的手机中卸载 android 应用程序时,PACKAGE_REMOVED 接收器将调用。您可以获得卸载的应用程序包名称 use intent,getDataString()

if (intent.getAction (). equals ("android.intent.action.PACKAGE_REMOVED")) {
          String packageName = intent.getDataString ();
          System.out.println ("uninstall:" + packageName + "package name of the program");  
}

See complete example in this link. http://foryouneed.blogspot.in/2014/08/android-listener-application-to-install.html

请参阅此链接中的完整示例。 http://foryouneed.blogspot.in/2014/08/android-listener-application-to-install.html