In Android development, if you use a database to store data, it is inevitable to look at the contents of the database, but for the root of the real machine, it is not so easy to view the database, if only to view the database and then put the phone root, a little more than the loss, So the following will provide a way to view the database without root, for the needs of friends reference.
1. Enter the directory where ADB is located, open the cmd window and enter ' adb shell'
2. Continue to enter the "Run-as App package name
Span class= "token MD Md-li" > 3. Then enter ' CD Databases "
< Span class= "token MD md-li" > 4. Last input ' Ls "View the name of the database
< Span class= "token MD md-li" >
< Span class= "token lf" >
My database name is App.db, then use the following code to move the database file to the folder that we can access
Private voidGetdatabasefiles () {//find the path to the file/data/data/package name/databases/database nameFile DBFile =NewFile (Environment.getdatadirectory (). GetAbsolutePath () + "/data/" +getpackagename () + "/databases/app.db"); FileInputStream FIS=NULL; FileOutputStream Fos=NULL; Try { //files are copied to SD cardFIS =NewFileInputStream (DBFile); FOS=NewFileOutputStream (Environment.getexternalstoragedirectory (). GetAbsolutePath () + "/copy.db"); intLen = 0; byte[] buffer =New byte[2048]; while( -1!= (len=fis.read (buffer))) {fos.write (buffer,0, Len); } fos.flush (); } Catch(Exception e) {e.printstacktrace (); }finally { //Turn off Data flow Try { if(Fos! =NULL) Fos.close (); if(FIS! =NULL) Fis.close (); } Catch(IOException e) {e.printstacktrace (); } } }
< Span class= "token lf" > < Span class= "token lf" > < Span class= "token lf" > then download a tool to view the database files , you can view the contents of the database. Hope can help you ~
ps: I developed a small application to make two-dimensional code, interested friends can try ~ ^_^ Creative Two-dimensional code production
< Span class= "token lf" > < Span class= "token lf" >
To view an app database for a root-rooted real machine in Android development