本文目录一览:
- 1、如何同时配置ADB变量环境和Java环境
- 2、电脑上的java软件怎么通过adb查询android sqlite数据库
- 3、用Java调用adb,不出来是为什么
- 4、java通过exec条用cmd执行adb无效
- 5、如何在Java代码中调用adb命令
如何同时配置ADB变量环境和Java环境
两个目录之间用半角的分号隔开,比如说:
path=D:\android-sdk-windows\tools;D:\jdk\bin
电脑上的java软件怎么通过adb查询android sqlite数据库
不知道,好像支持的我执行“adb shell cd /data/data/com.test/databases/ ls” 可以执行显示出databases下文件目录的,如果只用的话 就只显示根目录下的文件了
用Java调用adb,不出来是为什么
你需要在前面加上cmd /c
即exec中执行的命令应该是cmd /c adb shell input …
java通过exec条用cmd执行adb无效
“cmd.exe /c adb devices”
java的Runtime环境已经是命令行模式,类似已经打开cmd.exe 所以,
执行后续命令无需加上 cmd.exe,命令修改为:
Runtime.getRuntime().exec(“adb devices”)
如何在Java代码中调用adb命令
代码如下:
package com.symbio.ltp.adb;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import com.symbio.ltp.model.ConfigPropertiesData;
import com.symbio.ltp.util.Log;
public class ShellCommand {
private String name;
private Process process;
private BufferedWriter writer;
private BufferedReader reader;
private BufferedReader errorReader;
private ListString list;
private String[] returnValue;
public ShellCommand(String name) {
this.name = name;
}
public String getName() {
return name;
}
public Process getProcess() {
return process;
}
public BufferedWriter getOutputWriter() {
return writer;
}
public BufferedReader getInputReader() {
return reader;
}
public BufferedReader getErrorReader() {
return errorReader;
}
public boolean start(String cmd) {
try {
process = Runtime.getRuntime().exec(cmd);
writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
} catch (IOException e) {
Log.debug(“Exception in shell(” + name + “) — ” + e.getMessage());
return false;
}
return true;
}
public boolean exec(String cmd) {
String line;
try {
writer.write(cmd + “\n”);
writer.flush();
while((line = reader.readLine()) != null) {
Log.debug(line);
if(line.equals(ConfigPropertiesData.ltp_success)) {
return true;
} else if(line.equals(ConfigPropertiesData.ltp_fail)) {
return false;
}
}
} catch (IOException e) {
Log.debug(“Exception in shell(” + name + “) — ” + e.getMessage());
return false;
}
return true;
}
public String [] execReturn(String cmd) {
String line;
list = new ArrayListString();
try {
writer.write(cmd + “\n”);
writer.flush();
line = reader.readLine();
while((line = reader.readLine()) != null) {
if(line.length()0 !(line.startsWith(“#”))){
Log.debug(line);
list.add(line);
if(line.equals(ConfigPropertiesData.ltp_success)) {
break;
} else if(line.equals(ConfigPropertiesData.ltp_fail)) {
break;
}
}
}
int size = list.size();
returnValue = new String[size];
for (int i = 0; i size; i++) {
returnValue[i] = list.get(i);
}
} catch (IOException e) {
Log.debug(“Exception in shell(” + name + “) — ” + e.getMessage());
return null;
}
return returnValue;
}
public void terminate() {
try {
writer.write(0x03);
writer.flush();
} catch (IOException e) {
Log.debug(“Exception in shell(” + name + “) — ” + e.getMessage());
}
}
}
原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/241474.html