我想从使用 USB 连接到我的电脑的安卓手机发送短信。我正在起诉 usb4Java 库。我已根据链接usb4java-javax-examples访问手机并将 adb 命令发送到手机。这是代码和输出。
public static void main(String[] args) throws Exception {
....
AdbDevice device = devices.get(0);
device.open();
try {
// Send the connect message
Message message = new ConnectMessage(ConnectMessage.SYSTEM_TYPE_HOST, "12345678", "ADB Demo");
System.out.println("Sending: " + message);
device.sendMessage(message);
boolean connected = false;
while (!connected) {
message = device.receiveMessage();
System.out.println("Received: " + message);
// If connect message has been received then we are finished
if (message instanceof ConnectMessage) {
connected = true;
}
....
} // end of while
// Open "sync:"
message = new OpenMessage(1, "sync:");
System.out.println("Sending: " + message);
device.sendMessage(message);
message = device.receiveMessage();
System.out.println("Received: " + message);
if (!(message instanceof OkayMessage)) {
System.err.println("Open failed");
System.exit(1);
}
int remoteId = ((OkayMessage) message).getRemoteId();
// Close
message = new CloseMessage(1, remoteId);
System.out.println("Sending: " + message);
device.sendMessage(message);
message = device.receiveMessage();
System.out.println("Received: " + message);
}
}
这是我收到的输出
Sending: CONNECT(0x01000000, 4096, "host:12345678:ADB Demo")
Received: CONNECT(0x01000000, 4096, "device::")
Sending: OPEN(1, "sync:")
Received: OKAY(1, 1)
Sending: CLOSE(1, 1)
Received: CLOSE(0, 1)
有什么方法可以使用 Adb protpcol 向 android 手机发送短信命令,并且短信已发送。喜欢SENDSMS(int number, String textMessage)
。
还是有其他方法可以做到这一点?
谢谢
**编辑
这是我在做什么,但我正在接近(0, 1)。不知道做错了什么
message = new OpenMessage(1, "shell:command");
System.out.println("Sending: " + message);
device.sendMessage(message);
message = device.receiveMessage();
System.out.println("Received: " + message);
if (!(message instanceof OkayMessage)) {
System.err.println("Open failed");
System.exit(1);
}
int remoteId = ((OkayMessage) message).getRemoteId();
int localId = ((OkayMessage) message).getLocalId();
String num = "00923424700007";
String text = "Hello World";
message = new WriteMessage(remoteId, localId, "am start -a android.intent.action.SENDTO -d sms:"+num+" --es sms_body \""+text+"\" --ez exit_on_sent true");
System.out.println("Sending: " + message);
device.sendMessage(message);
message = device.receiveMessage();
System.out.println("Received: " + message);
if (!(message instanceof OkayMessage)) {
System.err.println("Open failed");
System.exit(1);
}
remoteId = ((OkayMessage) message).getRemoteId();
localId = ((OkayMessage) message).getLocalId();
我在网上做错了什么
message = new WriteMessage(remoteId, localId, "am start -a android.intent.action.SENDTO -d sms:"+num+" --es sms_body \""+text+"\" --ez exit_on_sent true");
谢谢