2

Hi i am developing application to read SMS using shell Commands (Only for Rooted Device )

Example Code

  • Runtime.getRuntime().exec("su -c \"mkdir /sdcard/testdir\"").waitFor(); --> To create directory
  • Runtime.getRuntime().exec("su"); --> Super User Permission
  • Runtime.getRuntime().exec("??"); --What is the Command To Read SMS
Gopinath Kaliappan
  • 6,929
  • 8
  • 37
  • 60
  • An answer to this question would be helpful for people who try to write a malicious app that steals data from users. In the hope that this is a [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem): You don't need root permissions to read SMS, [there is an official API](http://stackoverflow.com/questions/848728/how-can-i-read-sms-messages-from-the-inbox-programmatically-in-android) for that. The only "drawback" of using it is that your users will be notified that you're reading their messages. If you still need an answer, please elaborate on why you need it. – Phillip Jul 26 '16 at 11:30
  • Yes , i need answer for this question because i am creating application which can steal SMS from device ... this is the requirement .... Please note : this application is for schools students ... so their parents can track their activities .... – Gopinath Kaliappan Jul 26 '16 at 11:48

1 Answers1

7

to read any value from content resolver you can access it via its uri. like

adb shell content query --uri content://sms --projection _id,address,body,read,date,type

pass this command in exec, you will get the result like

Row: 0 _id=2, address=5554, body=Testing, read=1, date=1469533087074, type=2

Row: 1 _id=1, address=5554, body=Hi, read=1, date=1469533011944, type=2

you can get specific sms using specific uri

content://sms/inbox 
content://sms/sent

it will helpful to you.

Update

you can run it from java code like

Process process = Runtime.getRuntime().exec(new String[]{"su","-c","content query --uri content://sms --projection _id,address,body,read,date,type"});
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
RBK
  • 2,481
  • 2
  • 30
  • 52