首页 > 移动平台 > 详细

java,判断手机设备跟adb建立连接

时间:2021-08-30 14:02:44      阅读:19      评论:0      收藏:0      [点我收藏+]

代码如下:

package com.java.app01;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class IsDevicesConnect {
    public static void main(String[] args) throws Exception {
        boolean bool = isDevicesConnect();
        System.out.println(bool);

    }

    public static Boolean isDevicesConnect() {
        Process process;
        Runtime runtime = Runtime.getRuntime();
        String driverName = "";
        try {
            process = runtime.exec("adb devices");
            InputStream inputStream = process.getInputStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "GBK");
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String line;
            StringBuilder stringBuilder = new StringBuilder();
            while ((line = bufferedReader.readLine()) != null) {
                stringBuilder.append(line);
            }
            driverName = stringBuilder.toString();
            driverName = driverName.replaceAll("List of devices attached", "");
            driverName = driverName.replaceAll("\n", "");
            driverName = driverName.replaceAll("device", "");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (driverName != null && driverName.length() != 0) {
                System.out.println("获取到的设备名是:" + driverName);
                return true;
            }
            return false;
        }
    }
}

 

java,判断手机设备跟adb建立连接

原文:https://www.cnblogs.com/xiamaojjie/p/15195151.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!