views:

148

answers:

2

I have two versions of the same application.

When people upgrade from the free version to the paid version I'd like the free database to be copied to the pro database location.

Is there a way I can access the database file itself if it belongs to another application?
Does the file even belong to the application or is it generally accessible through the filesystem?

Finally, how do I get the path to the database file without hardcoding it?

+1  A: 

Where does the database file live? If it's on the SD card then you could probably access it directly. If you've created the DB in your private application directory then you won't be able to touch it. You could probably define a content provider in the free version of your app that the pro version could use to pull out all the info stored in the database.

jebcor
I'm using android's built in SQLite database support. The application manages the database file and location.
CodeFusionMobile
+2  A: 

Is there a way I can access the database file itself if it belongs to another application?

Only if both applications share a user ID and are signed by the same signing key.

Does the file even belong to the application or is it generally accessible through the filesystem?

It would be available via the filesystem (/data/data/your.package.goes.here/databases/whatever-you-called-the.db), but again, only if both applications share a user ID and are signed by the same signing key.

Finally, how do I get the path to the database file without hardcoding it?

You have to hardcode it, or at least the variable components (package name and database name), both of which you already know at compile time.

CommonsWare
Could I somehow use an Intent to request a copy?
CodeFusionMobile
Possibly. There's nothing built in for that. But, if nothing has a database handle open, it is just a file, so you can make a copy out to the SD card based on a broadcast Intent or something.
CommonsWare
I think I'm going to create a small activity in my free version specifically for transfer. I'll startactivityforresult with that intent, it will copy the database to common storage, the pro version will import it on return result_OK and that's that. I'll post a full solution when I get it working.
CodeFusionMobile