zoukankan      html  css  js  c++  java
  • 用Java实现adb命令的各种方式

    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/
    ".getBytes());
                 process.getOutputStream().write("rm -r Camera/ 
    ".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/
    ".getBytes());
                process.getOutputStream().write("ls
    ".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();
            }
            
            
        }
    
    }
     


  • 相关阅读:
    SQLServer2005安装提示服务无法启动解决方法
    如何处理SQL Server2005配置管理器打不开的问题!
    如何卸载oracle 10g数据库
    Gesture实现手势滑动效果
    为android虚拟机配置正确的DNS服务器地址
    a链接事件点击函数
    web 音频文件自动播放(兼容所有浏览器)
    关于Jquery中的$.each获取各种返回类型数据的使用方法
    jquery如何在异步方式中给全局变量赋值
    jquery的blur之后,focus获取不到焦点的解决办法
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/9708646.html
Copyright © 2011-2022 走看看