導航:首頁 > 編程語言 > 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相關的資料

熱點內容
伺服器共享文件夾怎麼查詢 瀏覽:114
為什麼雙路伺服器突然關機 瀏覽:690
51單片機定時器0任務調度 瀏覽:189
程序員編程語言經典合集epub 瀏覽:566
cadline未知命令 瀏覽:105
PLC的加密狗的作用 瀏覽:859
遺傳演算法優化神經網路權值閾值 瀏覽:288
伺服器為什麼要裝php 瀏覽:871
tomcat搭建android伺服器 瀏覽:340
怎麼下載app躲貓貓 瀏覽:888
極品飛車解壓資源包錯誤 瀏覽:703
pm2016免加密狗破解 瀏覽:439
拳擊pdf 瀏覽:346
柱子箍筋全長加密到板底 瀏覽:385
pdf頁面不一樣 瀏覽:302
javaphp混合 瀏覽:676
雲伺服器商業 瀏覽:193
永磁變頻螺桿式空氣壓縮機優缺點 瀏覽:368
程序員帶老婆回家 瀏覽:462
大學生編程學習資源 瀏覽:125