Android開發中查看未root真機的app資料庫

來源:互聯網
上載者:User

標籤:com   code   cti   移動   rect   資料庫   資料   src   environ   

在Android開發中,如果用到資料庫來儲存資料,那麼難免就要查看資料庫中的內容,可是對於未root的真機來說,查看資料庫就不是那麼容易了,如果僅僅為了查看資料庫再把手機root了,有點得不償失,所以下面的就提供了一中不用root也可查看資料庫的方法,供需要的朋友參考。

1. 進入adb所在的目錄,開啟cmd視窗,輸入`adb shell`

2. 繼續輸入`run-as 應用的包名`

3. 然後輸入 `cd databases`

4. 最後輸入`ls`查看資料庫的名字

如下:

,我的資料庫名字為 app.db,然後利用以下代碼把資料庫檔案移動到我們可以訪問的檔案夾下面

private void getDatabaseFiles(){        //找到檔案的路徑  /data/data/包名/databases/資料庫名稱        File dbFile = new File(Environment.getDataDirectory().getAbsolutePath()+"/data/"+getPackageName()+"/databases/app.db");        FileInputStream fis = null;        FileOutputStream fos = null;        try {            //檔案複製到sd卡中            fis = new FileInputStream(dbFile);            fos = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+"/copy.db");            int len = 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 {            //關閉資料流            try {                if (fos != null) fos.close();                if (fis != null) fis.close();            } catch (IOException e) {                e.printStackTrace();            }        }    }

然後下載一個可以查看資料庫檔案的工具,就可以查看資料庫的內容了。希望可以幫到你~

ps:自己開發了一個製作二維碼的小應用,有興趣的朋友可以試一試~ ^_^ 創意二維碼製作

Android開發中查看未root真機的app資料庫

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.