import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SmsIdQuery {
public static void main(String[] args) {
String cmd = "adb shell content query --uri content://sms/sent --projection _id --limit 1"; // 内容提供器URI和查询参数
try {
Process proc = Runtime.getRuntime().exec(cmd); // 执行命令
BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
String s = null;
while ((s = stdInput.readLine()) != null) { // 读取命令的输出结果
System.out.println("sms id: " + s.trim()); // 输出结果中的ID
}
while ((s = stdError.readLine()) != null) { // 读取错误流
System.out.println(s);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}