博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用Java实现adb命令的各种方式
阅读量:4926 次
发布时间:2019-06-11

本文共 3965 字,大约阅读时间需要 13 分钟。

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();		}					}}
posted on
2018-03-21 13:56  阅读(
...) 评论(
...) 收藏

转载于:https://www.cnblogs.com/guanxinjing/p/9708646.html

你可能感兴趣的文章
JavaWeb学习记录(二十六)——在线人数统计HttpSessionListener监听实现
查看>>
Fibonacci数列 与 杨辉三角
查看>>
音频视频播放(jquery中将jquery方法转化成js方法)
查看>>
Linux设备驱动开发基础--阻塞型设备驱动
查看>>
Hadoop综合大作业
查看>>
ES6 语法之import export
查看>>
网页上实现 Project 甘特图
查看>>
AttributeError: '_csv.reader' object has no attribute 'next'
查看>>
八大排序算法
查看>>
Meteor部
查看>>
WindowsPhone 在 根据公历 获取月球日期数据
查看>>
数字金额大小写转换
查看>>
【翻译mos文章】Linux x86 and x86-64 系统SHMMAX最大
查看>>
AWS Credentials 使用
查看>>
iOS 多线程,ARC
查看>>
Javascript小技巧,去掉小数位并且不会四舍五入
查看>>
指定初始化方法
查看>>
使用eclipse进行重构
查看>>
vs mfc 静态文本 改变字体大小
查看>>
Hidden Word
查看>>