导航:首页 > 编程语言 > adbjava

adbjava

发布时间:2024-11-20 09:47:09

‘壹’ 如何在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 List<String> 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 ArrayList<String>();
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());
}
}
}

‘贰’ java大神 小弟最近准备学安卓 cmd输入adb有很多东西 说明成功了 可是运行sdk man

就现在开发而言的话,模拟器需要一个2.2的版本,然后一个4.0的版本,4.0以上的版本任意一个(我现在用的4.4)。不过对于你现在只是学习的话,不需要这么多版本,随便下一个,4.2这个版本还不错。实际开发的时候公司一般情况下都会拿平板来做测试。模拟器跑起来太卡了

阅读全文

与adbjava相关的资料

热点内容
word转换成pdf转换器免费下载 浏览:608
群体智能基本算法 浏览:370
可编程软件分为哪两种 浏览:340
格林什么app可以看 浏览:697
飞卢app仙侠热卖推荐怎么样 浏览:722
飞秋上传文件到共享文件夹 浏览:691
服务器的共享文件夹如何访问 浏览:232
复盛螺杆压缩机讲解 浏览:332
柱在基础插筋需要加密吗 浏览:80
51单片机中断寄存器 浏览:65
压缩文件后有病毒怎么办 浏览:618
苹果ipad怎么登安卓王者账号 浏览:862
街头足球服务器已满是什么意思 浏览:462
androidspeex回音消除 浏览:133
加密会议什么意思 浏览:34
ubuntu命令行联网 浏览:7
37选7中奖概率及算法 浏览:593
加密狗哪个版本好 浏览:619
cisco命令手册 浏览:502
omp算法c 浏览:129