How to handle application upgrades from free to paid version while preserving any data
Here is the context. I want to have a free version and a premium version of the same application. When people buy the application, I want them to be able to "upgrade" without losing their data, i.e. the premium version should install over the free version. I want to use the same code base and just switch a setting to build the premium version. Andoid Market does not let me convert a free app to a paid app, so the trivia开发者_开发百科l option is not available.
I am curious if someone has tried this successfully. How does Android Market identify an application - will it think that the premium version is a different app and just install it in parallel?
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.
My idea is the following:
- Paid version's
android:versionCode
should be free'sandroid: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.
精彩评论