02-18-2011 03:58 PM
My application packages a pre-existing SQLite file as a resource, which it stores at //sdcard/databases/[appName]/db.sql.
My problem is when users have their devices set to encrypt the Media Card, I can put the file on the card but my app cannot access it or decrypt it, and therefore I'm unable to use it.
Is there a way I have my app decrypt the .sql file, or prevent it from encrypting on the card in the first place? This seems like it could be a common use case.
I've found a funky work around by renaming the .sql to .mp3, but again this will only work if the user has Media Files encryption set to "Disabled." This is non-ideal, obviously.
Solved! Go to Solution.
02-23-2011 11:41 AM
This is a known issue. Fortunately the following workaround should resolve the issue for you:
Instead of download the .db file and then opening it directly in SQLite using the DatabaseFactory class, proceed as follows:
1. Create the database(file) using the DatabaseFactory class.
2. Close the database.
3. Open a file connection to the database file that was created in step 1 and 2
4. Truncate the file to 0 by calling FileConnection.truncate(0)
5. Download the database over the network and write out the data to the file created above using FileConnection.openOutputStream()
6. Close the file connection
7. Now, re-open the database using the DatabaseFactory class and your SQL should work as expected.
Creating the database file using the DatabaseFactory class results in the file *not* being marked as requiring encryption.
Hope this works for you.