Skip to content Skip to sidebar Skip to footer

How To View Sqlite Database In Android Application At Run Time

I am trying to copy data from DDBMS perspective -> file explorer -> data -> [my_app_package] then PULL this is working when I am running application on emulator but when I

Solution 1:

One can surely retreive database .db file from Android Device programmatically. I used to put one more setting under my application named Developer Options which copy .db file into sdCard.

Following code copy .db to sdcard. Change your copied .db file name into whatever like to with backupDBPath and currentDBPath (Name which you gave to your database name).

publicvoiddev()
    {
        try {
            Filesd= Environment.getExternalStorageDirectory();
            Filedata= Environment.getDataDirectory();

            if (sd.canWrite()) {
                StringcurrentDBPath="/data/data/" + getPackageName() + "/databases/ZnameDB";
                StringbackupDBPath="ZnameDB_Dev.db";
                FilecurrentDB=newFile(currentDBPath);
                FilebackupDB=newFile(sd, backupDBPath);

                if (currentDB.exists()) {
                    FileChannelsrc=newFileInputStream(currentDB).getChannel();
                    FileChanneldst=newFileOutputStream(backupDB).getChannel();
                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();
                    Toast.makeText(SettingsActivity.this, "Database Transfered!", Toast.LENGTH_SHORT).show();
                }
            }
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }
  }

There are many application available in PlayStore with which you can view your .db file. I used aSQLiteManager android application to view .db file.

Solution 2:

No you can't,how ever you can use logs to fetch and see the fetched data in logcat or set some value on your textviews or use table layout too see your fetched data .However the best way is using SQLiteBrowser.You can pull the database file from your emulator or device and then save it on your hard disk and browse it in Sqlitebrowser.

Solution 3:

You can copy your sqlite file to sdcard programmatically. Follow this link. And view it using any Sqlite Viewer.

Post a Comment for "How To View Sqlite Database In Android Application At Run Time"