不root的情況下 查看App的資料表

來源:互聯網
上載者:User

標籤:android   style   blog   http   color   ar   os   使用   java   

一直以來查看sqlite的資料庫都需要root才能查看,但是公司的好多測試機root起來比較麻煩~~~

最近剛好項目上線,略閑,

於是決定寫一個library工程便於以後調試代碼

關鍵代碼如下

一、查看當前app的資料庫

context.databaseList()
其中databaseList方法是ContextWrapper類中的一個方法定義如下
 @Override

    public String[] databaseList() {        return mBase.databaseList();    }

二、查看庫中的資料表

SQLiteDatabase db = dbHelper.getWritableDatabase();Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);if (c.moveToFirst()) {while (!c.isAfterLast()) {tables.add(c.getString(0));//資料表c.moveToNext();}}

三、查看資料表中的資料

DbHelper db = new DbHelper(getContext(), databaseName);Cursor c = db.getWritableDatabase().query(tableName, null, null, null, null, null, null);String[] columnNames = c.getColumnNames();ArrayList<String> datas = new ArrayList<String>();StringBuilder sb = new StringBuilder();if (c.moveToFirst()) {while (!c.isAfterLast()) {sb.setLength(0);for (String columnName : columnNames) {int columnIndex = c.getColumnIndex(columnName);String colValue = c.getString(columnIndex);sb.append(columnName).append(": ").append(colValue).append("\n");}datas.add(sb.toString());Log.d("table_" + tableName, sb.toString());c.moveToNext();}}

以上代碼除了databaseList() 這個方法查了好久以外,其他還相對簡單點


其中。查看app表的資料剛開始打算仿照root explorer做一個瀏覽資料的控制項。但是想了一下感覺比較複雜,目前還未實現

工程的連結在此

https://github.com/droidcoffee/yolanda/tree/master/yolanda_Android


注意使用方法,將工程作為一個library工程引入

同時修改主工程的project.properties檔案增加如下配置即可。

manifestmerger.enabled=true
這樣可以使library中AndroidManifest.xml中配置的Activity生效。

也就是不用copy到主工程中重新設定了。


遇到問題的大家可以加群299306868

不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.