简体   繁体   English

在更新时完全卸载并重新安装Android应用程序?

[英]Completely uninstall and reinstall Android app on update?

I want to publish a new version of my app. 我想发布我的应用程序的新版本。 But I want it to reinstall again. 但是我希望它能够重新安装。

Like first uninstall and then install(like first time installation). 像首先卸载然后安装(如第一次安装)。 Is there anyway that I can do it? 无论如何我能做到吗? Or force users to first uninstall the app? 或强制用户首先卸载应用程序?

If you sign the new apk with a different key, users will hit an error when they try to upgrade an existing installation. 如果您使用其他密钥对新apk进行签名,则用户在尝试升级现有安装时会遇到错误。 That's probably the easiest way to do it without changing the package name. 这可能是最简单的方法,无需更改包名称。

As Jens said you can't do this really unless you reinstall with a different package name (not a good idea either.) You have to detect your version and manually reset your preferences etc. if you need to. 正如Jens所说,除非你重新安装不同的软件包名称,否则你无法做到这一点(也不是一个好主意。)如果需要,你必须检测你的版本并手动重置你的偏好等。 This is a pretty annoying feature of android. 这是一个非常烦人的android功能。 I've been developing a mapping application that has the exact same problem with storing some of the background data. 我一直在开发一个映射应用程序,它与存储一些后台数据有着完全相同的问题。

You can usually check where your preferences get created for the first time. 您通常可以首次检查首选项的创建位置。 A lot of people do a if(preference !=null) to set them up, since in a pre-installed app you already have that preference in the bundle it will not update or generate a new one. 很多人都会使用if(preference!= null)来设置它们,因为在预先安装的应用程序中,您已经在bundle中拥有该首选项,它将不会更新或生成新的首选项。

Try setting the preference checker to be if(preference != newValueOfPreference) 尝试将首选项检查器设置为if(preference!= newValueOfPreference)

If that's not how your bundle data is generated on install you'll have to find out how it is generated and get at that hook. 如果这不是您在安装时生成捆绑数据的方式,那么您必须了解它是如何生成的并从中获取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM