How to handle application upgrades from free to paid version while preserving any data

坚强是说给别人听的谎言 提交于 2019-11-29 08:21:26

My idea is the following:

  • Paid version's android:versionCode should be free's android:versionCode +1
  • Both should have the same package.

When paid version is installed, it will replace the free one. Actually it will update it, since it has a higher android:versionCode.

As both have the same package, they will be placed in the same folder ( /data/data/your.package) so the paid app will be able to access the free app db.

The answer is: this is not solvable with Android Market, because Market does not allow the upload of two apps with the same package name. Android cannot be tricked into installing the premium version over the free version and treat it as an upgrade.

The good news: adding database backup/restore functionality (copying the database to the SD card and back to the app folder) only required a few lines of code. My users will have to install both versions in parallel, back up the database from the free version and restore it to the premium version.

Instead of backing up the database to and from the SD card (as suggested by @cdonner), which requires the WRITE_EXTERNAL_STORAGE permission, the free app can expose a ContentProvider, which the paid app can use to transfer data.

Be sure to use permissions to secure your content.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!