App database for Android development in view of root-rooted real machine

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.