温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何实现Android手机通过WIFI和PC连接

发布时间:2021-11-20 16:46:43 来源:亿速云 阅读:293 作者:小新 栏目:移动开发

这篇文章主要介绍如何实现Android手机通过WIFI和PC连接,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

1.在程序中通过

Runtime.getRuntime().exec("su");

获得手机root权限(手机必须是root之后的)。

2.重新启动adbd

exec("stop adbd"); exec("start adbd");

3.与PC建立连接(我是通过bat文件进程处理的)

/**          * 手机连接wifi.          *          * @param host 手机ip:端口号。例如:192.168.10.124:8888          */         public int connectWifi(String host) {             String cmd = ParseProperties.getProperties("dir")                     + "bin/ConnectWifi.bat " + host;             BufferedReader reader = null;             int retcode = 0;             try {                 Process process = Runtime.getRuntime().exec(cmd);                       reader = new BufferedReader(new InputStreamReader(                         process.getInputStream()));                 @SuppressWarnings("unused")                 String line = null;                 String returnLine = null;                 System.out.println("*****************************");                 while ((line = reader.readLine()) != null) {                     if (line != null)                         returnLine = line;                     System.out.println(line);                 }                 if (returnLine.trim().startsWith("connected to")) {                     retcode = SUCCESS;                 } else if (returnLine.trim().startsWith("already connected to")) {                     retcode = SUCCESS;                 } else {                     retcode = FAILE;                 }                 System.out.println("*****************************");             } catch (IOException e) {                 e.printStackTrace();                 retcode = FAILE;             } finally {                 if (reader != null) {                     try {                         reader.close();                     } catch (Exception e) {                         e.printStackTrace();                     }                 }             }             if (retcode == 0) {                 retcode = FAILE;             }             return retcode;         }

bat文件

bat文件中的内用很简单 adb connect %1

通过上述方法就能通过wifi和PC连接在一起了。注意:手机和PC机要在同一个局域网中。

以上是“如何实现Android手机通过WIFI和PC连接”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI