当前位置:   article > 正文

java adb_用Java实现adb命令的各种方式

java adb

packagecom.function;importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.DataOutputStream;importjava.io.IOException;importjava.io.InputStreamReader;importjava.io.OutputStreamWriter;importcom.sql.Tools_Sql;/** adb 命令方法集合类*/

public classTools_AdbCommand {/** 拍照实现方法*/

public voidtaking_pictures() {try{

Process process= Runtime.getRuntime().exec("cmd /c adb shell input keyevent 27");

Thread.sleep(3000);

process.destroy();

}catch(IOException e) {//TODO Auto-generated catch block

e.printStackTrace();

}catch(InterruptedException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}/** 对焦实现方法*/

public voidfocusing() {try{

Process process= Runtime.getRuntime().exec("cmd /c adb shell input keyevent 80");

Thread.sleep(2000);

process.destroy();

}catch(InterruptedException e) {//TODO Auto-generated catch block

e.printStackTrace();

}catch(IOException e1) {//TODO Auto-generated catch block

e1.printStackTrace();

}

}/** 删除手机照片文件方法*/

public voiddeletecamerafile() {try{

Process process= Runtime.getRuntime().exec("adb shell");

BufferedReader input= new BufferedReader(newInputStreamReader(process.getInputStream()));

process.getOutputStream().write("cd /mnt/sdcard/DCIM/\r\n".getBytes());

process.getOutputStream().write("rm -r Camera/ \r\n".getBytes());

process.getOutputStream().flush();//刷新流

Thread.sleep(2000);

input.close();

process.destroy();

System.out.println("手机中的照片清除完毕...");

}catch(IOException e) {//TODO: handle exception

e.printStackTrace();

}catch(InterruptedException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}/** pull照片的 方法*/

public voidpullphoto(String path,String Storage_place) {

get_photo_name(Storage_place);

Process process2 ;try{if(Storage_place == "contrast_photo") {

process2= Runtime.getRuntime().exec("cmd /c adb pull /mnt/sdcard/DCIM/Camera/"+new Tools_Sql().getcontrast_photo_name()+" "+path);

Thread.sleep(3000);

process2.destroy();

}else if (Storage_place=="test_photo") {

process2= Runtime.getRuntime().exec("cmd /c adb pull /mnt/sdcard/DCIM/Camera/"+new Tools_Sql().getTest_photo_name()+" "+path);

Thread.sleep(3000);

process2.destroy();

}else if (Storage_place == "error_photo") {

process2= Runtime.getRuntime().exec("cmd /c adb pull /mnt/sdcard/DCIM/Camera/"+new Tools_Sql().getTest_photo_name()+" "+path);

Thread.sleep(3000);

process2.destroy();

}

System.out.println("照片从手机上下载完成....");

}catch(IOException e) {//TODO Auto-generated catch block

e.printStackTrace();

}catch(InterruptedException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}/** 得到当前测试照片名称的方法*/

public voidget_photo_name(String Storage_place) {try{

Process process= Runtime.getRuntime().exec("adb shell");

BufferedReader input= new BufferedReader(newInputStreamReader(process.getInputStream()));

process.getOutputStream().write("cd /mnt/sdcard/DCIM/Camera/\r\n".getBytes());

process.getOutputStream().write("ls\r\n".getBytes());

process.getOutputStream().flush();

String s=input.readLine();if(Storage_place == "contrast_photo") {newTools_Sql().setcontrast_photo_name(s);

System.out.println("照片名称是:"+newTools_Sql().getcontrast_photo_name());

}else if (Storage_place == "test_photo") {newTools_Sql().setTest_photo_name(s);

System.out.println("照片名称是:"+newTools_Sql().getTest_photo_name());

}else if (Storage_place == "error_photo") {newTools_Sql().setTest_photo_name(s);

System.out.println("照片名称是:"+newTools_Sql().getTest_photo_name());

}

input.close();

process.destroy();

}catch(IOException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/335620
推荐阅读
相关标签
  

闽ICP备14008679号