最近一段事件一直在研究如何用wifi和PC连接,但是在网上找了很久,也看过很多例子。都没有成功。无奈只好自己研究。***自己写了一个小Demo。分享一下。[[69567]]

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、雅安服务器托管、营销软件、网站建设、延庆网站维护、网站推广。
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连接
                
                标题链接:http://www.csdahua.cn/qtweb/news23/104273.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网