0

I have to develop an app that reads messages from whatsapp database.

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void sendMessage(View view){
        try{
            Process p = Runtime.getRuntime.exec(new String[] {"sqlite3", 
                "/data/data/com.whatsapp/databases/msgstore.db", 
                "select * from messages;"});
        }
        catch(Exception e){
            textView4.setText(e.getMessage());
        }
    }
}

Only when I make mistake with sqlite3(e.g. sqlite34 in stead of sqlite3), an error comes. But when I make mistakes in the other statements(e.g. databs in stead of databases), no error come. This means exec fires only the first statement, the other two statements would not be fired.

CL.
  • 173,858
  • 17
  • 217
  • 259
user7396065
  • 39
  • 1
  • 7

1 Answers1

0

exec() succeeds when it has managed to started that process.

To find out the return value of the sqlite3 process, you have to use the Process object to wait for it to end, and then to read its exit value.

CL.
  • 173,858
  • 17
  • 217
  • 259
  • thank you very much for your answer, was very helpfull. I have another question. In order to insert data in com.whatsapp/databases i need root permissions, how should i do that? i have tried that: rt.exec(new String[]{"su", "sqlite3", "/data/data/com.whatsapp/databases/msgstore.db", "insert ....."}); and in the Manifest data: but it doesnt work. Have you probably any idea?thank you again – user7396065 Mar 29 '17 at 12:37
  • This is not a forum. To ask a question, click "Ask Question". – CL. Mar 29 '17 at 13:56