如何在root用户设备中使用shell命令读取短信?

时间:2016-07-04 12:16:29

标签: java android shell

您好我正在开发应用程序以使用shell命令读取SMS(仅适用于Root设备)

示例代码

  
      
  • Runtime.getRuntime()。exec(" su -c \" mkdir / sdcard / testdir \"")。waitFor(); - >创建目录
  •   
  • 调用Runtime.getRuntime()EXEC键。("苏&#34); - >超级用户许可
  •   
  • 调用Runtime.getRuntime()EXEC键。(" ??&#34); - 什么是命令阅读短信
  •   

1 个答案:

答案 0 :(得分:3)

从内容解析器中读取任何值,您可以通过其uri访问它。像

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

在exec中传递此命令,您将获得类似

的结果
  

行:0 _id = 2,地址= 5554,body =测试,读取= 1,日期= 1469533087074,   type = 2

     

行:1 _id = 1,地址= 5554,body = Hi,read = 1,   date = 1469533011944,type = 2

您可以使用特定的uri获取特定的短信

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

它对你有帮助。

<强>更新

你可以从像

这样的java代码运行它
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()));