I did this using the following code:
public void copyDbToSdcard() { try { String comando = "cp -r /data/data/com.whatsapp/databases/msgstore.db /sdcard/My_Custom_Folder/"; Process suProcess = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(suProcess.getOutputStream()); os.writeBytes(comando + "\n"); os.flush(); os.writeBytes("exit\n"); os.flush(); try { int suProcessRetval = suProcess.waitFor(); if(255 != suProcessRetval) { // } else { // } } catch (Exception ex) { Log.e("ERROR-->", ex.toString()); } } catch (Exception e) { e.printStackTrace(); } } private void openAndQueryDatabase() { try { DataBaseHelper dbHelper = new DataBaseHelper(this.getApplicationContext()); newDB = dbHelper.getWritableDatabase(); Cursor c = newDB.rawQuery("SELECT data FROM messages where data!=''", null); if(c != null) { if(c.moveToFirst()) { do { String data = c.getString(c.getColumnIndex("data")); results.add(data); //adding to arrayList } while (c.moveToNext()); } } while (c3.moveToNext()); } } } catch (SQLiteException se) { Log.e(getClass().getSimpleName(), "Could not create or Open the database"); } }
And then display the results in a TextView or, if you want.
Greetings! :)
Noman
source share