I create a application that use SQLite database and insert some data and then I need this full sqlite database file and i try to acces it but I didnot found database file, How to acces this file for use my PC?
1 Answer
If you are using Emulator then you can access your database, just by pulling it out from File Manager from following path: data/data/com.my.package/databases/mydb.sqlite
If you are running your application on your device then use following code to get database from your above filePath (since you cannot access internal file system of android device)
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "/data/com.yourApp.common/databases/yourApp.db";
String backupDBPath = "/yourApp.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB)
.getChannel();
FileChannel dst = new FileOutputStream(backupDB)
.getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
}
After that, once you have your db file, you can view it from Mozilla add On (Plugin) called SQLte Manager. Use this: https://addons.mozilla.org/en-us/firefox/addon/sqlite-manager/ to download it.
3 Comments
Shrikant Ballal
you don't need to root your device, just write above code somewhere in your app, and view your database.
katsu
how to this line "sd.canWrite()" is true?
Shrikant Ballal
It will only work if you have provided permission in manifest file as "EXTERNAL_STORAGE" as you are going to store your db file on SD card.