How can I see the contents of sqlite db of my application in a real device?

I want to see the contents of my database created in my application on the device that I denounced. I can use sqlite commands in the shell and see in the emulator, but not in the real device.

Does anyone know how to do this on a real device?

+4
source share
5 answers

root is not required if the application is marked as debugged. You can use the run-as adb command.

eg. use sqlite:

 adb shell "run-as com.your.package sqlite3 databases/database_name" 

or copy and pull the database:

 adb shell "run-as com.your.package cat databases/database_name > /sdcard/some_name" adb pull /sdcard/some_name 

Unfortunately, it seems that pre-ICS run-as has quite a few errors, for example. issue 20792 or 13965

+7
source

In fact, your Real Device is not rooted , so you do not have access to the /data/data/<Application>/database/ directory .

Only one solution copies this file to external storage .. And look it up in SQLiteManager or other SQLite tools.

+2
source

I think you need an rooted device to access sqlite.

Take a look at the discussion .

+1
source

Try it,

You can copy your database to your SD card, where you can see your database

  public void backup() { try { File sdcard = Environment.getExternalStorageDirectory(); File outputFile = new File(sdcard, "YourDatabase.db"); if (!outputFile.exists()) outputFile.createNewFile(); File data = Environment.getDataDirectory(); File inputFile = new File(data, "data/"+getPackageName()+"/databases/"+"YourDatabase.db"); InputStream input = new FileInputStream(inputFile); OutputStream output = new FileOutputStream(outputFile); byte[] buffer = new byte[1024]; int length; while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } output.flush(); output.close(); input.close(); } catch (IOException e) { e.printStackTrace(); throw new Error("Copying Failed"); } } 

Hope this helps.

0
source

Try this feature as

copyFile(new File("data/data/<app>/database"),new File("mnt/sdcard/....")) .

 public void copyFile(File filesrc, File filedst) { try { FileInputStream localFileInputStream = new FileInputStream(filesrc); FileOutputStream localFileOutputStream = new FileOutputStream(filedst); byte[] arrayOfByte = new byte[1024]; while (true) { int i = localFileInputStream.read(arrayOfByte); if (i == -1) { localFileOutputStream.close(); localFileInputStream.close(); break; } localFileOutputStream.write(arrayOfByte, 0, i); } } catch (Exception localException) { Log.d("XXX", "ExceptioncopyFile:" + localException.getMessage(), localException); } 

}

0
source

Source: https://habr.com/ru/post/914451/


All Articles