package com.function; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import com.sql.Tools_Sql; /* * adb 命令方法集合类 */ public class Tools_AdbCommand { /* * 拍照实现方法 */ public void taking_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 void focusing() { 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 void deletecamerafile() { try { Process process = Runtime.getRuntime().exec("adb shell"); BufferedReader input = new BufferedReader(new InputStreamReader(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 void pullphoto(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 void get_photo_name(String Storage_place) { try { Process process = Runtime.getRuntime().exec("adb shell"); BufferedReader input = new BufferedReader(new InputStreamReader(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" ) { new Tools_Sql().setcontrast_photo_name(s); System.out.println("照片名称是:"+new Tools_Sql().getcontrast_photo_name()); }else if (Storage_place == "test_photo") { new Tools_Sql().setTest_photo_name(s); System.out.println("照片名称是:"+new Tools_Sql().getTest_photo_name()); }else if (Storage_place == "error_photo") { new Tools_Sql().setTest_photo_name(s); System.out.println("照片名称是:"+new Tools_Sql().getTest_photo_name()); } input.close(); process.destroy(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
本文来自博客园,作者:观心静 ,转载请注明原文链接:https://www.cnblogs.com/guanxinjing/p/9708646.html
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具