First of all I have done a search and can't find a specific answer to my question so here goes...
I am writing my first Android application and plan to have a Lite version (limited features) and a paid version (full features).
The Lite and Pro version will use the same SQLite database structure, and if the user starts with the Lite version and upgrades to the Pro version, I dont want them to lose the data they have created in the Lite version.
As the Lite and Pro versions will (from my understanding) have to be in separate packages to allow the Android Market to distinguish between them, how can the Pro version see the Lite database?
Many thanks in advance for your answers.
SQLite is very well-suited as a device-resident data manager. It is an application library and not a client-server database, making it very flexible for applications to use. SQLite has a simple API that you use from inside your code.
Android SQLite is the mostly preferred way to store data for android applications. For many applications, SQLite is the apps backbone whether it's used directly or via some third-party wrapper. Below is the final app we will create today using Android SQLite database.
SQLite is very good for testing. Zero-configuration: SQLite doesn't need any complex set up to store the data. When you build Native applications with Java, it comes integrated with the platform. Developers call SQLite, a serverless database and it really lives up to the expectation.
SQLite Database is an open-source database provided in Android which is used to store data inside the user's device in the form of a Text file. We can perform so many operations on this data such as adding new data, updating, reading, and deleting this data.
What I did in and it seems to work for Hexaddicus, is have both Lite and Pro versions run as the same user and then on the first time run of the Pro version, copy the Lite database over. Then inform the user of the copy.
Set the android:sharedUserId
to be the same in both products...
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.package"
android:sharedUserId="com.mycompany.package" <---- IMPORTANT
android:versionCode="10"
android:versionName="@string/app_version"
android:installLocation="auto">
And then the code to copy the DB...
try {
final Context free_context = this.createPackageContext("com.mycompany.package", Context.CONTEXT_INCLUDE_CODE);
final File full_db = this.getDatabasePath(GameData.DATABASE_NAME);
final File full_db_dir = full_db.getParentFile();
final File free_db = free_context.getDatabasePath(GameData.DATABASE_NAME);
final File free_db_dir = free_db.getParentFile();
if (free_db.exists() == false) return;
if (full_db_dir.exists() == false) full_db_dir.mkdir();
if (full_db.exists() == false) full_db.createNewFile();
FileUtils.copyDirectory(free_db_dir, full_db_dir);
this.gameData.getWritableDatabase();
}
catch (NameNotFoundException e) {
/* do nothing here since this is an semi expected case */
Log.w("mytag", "No Lite version found");
} catch (IOException e) {
Log.w("mytag", "Failed to create file");
}
}
The only downside of this is that once the copy is done, there is no syncing between the two versions. You also have to make sure that the user of the Lite version is running a version that is running as the sharedUserId
or the copy will fail.
Update: please consider ChrisCashwells comments and answer too since he brings up a valid point and I can't remember what I did in his example.
You might want to do more of an "unlock" approach than a separate paid app if possible. That way you're only ever using one package. If for no other reason, you'll be avoiding the issue of database ownership.
Using the same android:sharedUserId
would be a good approach if your app already has one set. If not, you'll invalidate access to all of your users' data if you send out an update that does have one set. If you're starting from square zero and don't already have an app in the wild with users expecting to keep their data, definitely set a sharedUserId
from day one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With