0

I have a query, If I run any android application on my emulator, I can check its database from the

data--> data--> package name folder--> databases--> database name.db file

and then accessing it with

SQLite Browser

But if I want to access the database on my Android Mobile Device, how can I do so. I had searched a lot but could find how to access or see the database in android mobile device of a particular app. Any help will be appriciated.

Pravinsingh Waghela
  • 2,516
  • 4
  • 32
  • 50

2 Answers2

5

An alternate solution is to copy the database to your SD Card and access it from there

To copy database file:

File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
FileChannel source = null;
FileChannel destination = null;
String currentDBPath = "/data" + context.getPackageName() + "/databases/" + DATABASE_NAME;
String backupDBPath = FOLDER_NAME + NEW_DATABASE_NAME;
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
try {
    source = new FileInputStream(currentDB).getChannel();
    destination = new FileOutputStream(backupDB).getChannel();
    destination.transferFrom(source, 0, source.size());
    source.close();
    destination.close();
} catch (IOException e) {
    e.printStackTrace();
}

Now you have your required database file at the given location in your SD card specified by backupDBPath. It can accessed either by SQLite Browser by pulling the db file or by using a Eclipse plugin http://www.4shared.com/file/usHZdRdz/comquestoidsqlitemanager_100.html?locale=en by which it can be accessed inside Eclipse itself.

Sky Kelsey
  • 19,192
  • 5
  • 36
  • 77
vinv
  • 355
  • 2
  • 14
2

You can only access the sqlite.db from your emulator. You cannot view the db from your mobile phone due to security restrictions.

I had this same requirement and on searching found out that it is possible when using a rooted device. Then I came up with this alternative.

  1. Test all the mobile SQLite Data related stuff on emulator.
  2. While testing in mobile phone connected via USB, log all the data that is accessed from SQLite of mobile, so that it can be viewed in logcat.
ngrashia
  • 9,869
  • 5
  • 43
  • 58