实现android手机通过WIFI和PC连接。
2014-03-14 15:42
786 查看
实现android手机通过WIFI和PC连接。
发表于11个月前(2013-04-07 16:20) 阅读(4671) | 评论(23)
101人收藏此文章,
我要收藏
赞1
WIFI
wifi
android手机
android手机通过wifi连接电脑
最近一段事件一直在研究如何用wifi和PC连接,但是在网上找了很久,也看过很多例子。都没有成功。无奈只好自己研究。最后自己写了一个小Demo。分享一下。
![](http://my.oschina.net/js/ke/plugins/emoticons/images/0.gif)
1.在程序中通过
view source
print?
获得手机root权限(手机必须是root之后的)。
2.重新启动adbd
view source
print?
3.与PC建立连接(我是通过bat文件进程处理的)
view source
print?
bat文件
bat文件中的内用很简单 adb connect %1
通过上述方法就能通过wifi和PC连接在一起了。注意:手机和PC机要在同一个局域网中。
发表于11个月前(2013-04-07 16:20) 阅读(4671) | 评论(23)
101人收藏此文章,
我要收藏
赞1
WIFI
wifi
android手机
android手机通过wifi连接电脑
最近一段事件一直在研究如何用wifi和PC连接,但是在网上找了很久,也看过很多例子。都没有成功。无奈只好自己研究。最后自己写了一个小Demo。分享一下。
![](http://my.oschina.net/js/ke/plugins/emoticons/images/0.gif)
1.在程序中通过
view source
print?
1 | Runtime.getRuntime().exec( "su" ); |
2.重新启动adbd
view source
print?
1 | exec( "stop adbd" ); |
2 | exec( "start adbd" ); |
view source
print?
01 | /** |
02 | * 手机连接wifi. |
03 | * |
04 | * @param host 手机ip:端口号。例如:192.168.10.124:8888 |
05 | * @return retcode 成功:1 ,失败:2 |
06 | */ |
07 | public int connectWifi(String host) { |
08 | String cmd = ParseProperties.getProperties( "dir" ) |
09 | + "bin/ConnectWifi.bat " + host; |
10 | BufferedReader reader = null ; |
11 | int retcode = 0 ; |
12 | try { |
13 | Process process = Runtime.getRuntime().exec(cmd); |
14 |
15 | reader = new BufferedReader( new InputStreamReader( |
16 | process.getInputStream())); |
17 | @SuppressWarnings ( "unused" ) |
18 | String line = null ; |
19 | String returnLine = null ; |
20 | System.out.println( "*****************************" ); |
21 | while ((line = reader.readLine()) != null ) { |
22 | if (line != null ) |
23 | returnLine = line; |
24 | System.out.println(line); |
25 | } |
26 | if (returnLine.trim().startsWith( "connected to" )) { |
27 | retcode =SUCCESS; |
28 | } else if (returnLine.trim().startsWith( "already connected to" )) { |
29 | retcode =SUCCESS; |
30 | } else { |
31 | retcode =FAILE; |
32 | } |
33 | System.out.println( "*****************************" ); |
34 | } catch (IOException e) { |
35 | e.printStackTrace(); |
36 | retcode =FAILE; |
37 | } finally { |
38 | if (reader != null ) { |
39 | try { |
40 | reader.close(); |
41 | } catch (Exception e) { |
42 | e.printStackTrace(); |
43 | } |
44 | } |
45 | } |
46 | if (retcode == 0 ) { |
47 | retcode =FAILE; |
48 | } |
49 | return retcode; |
50 | } |
bat文件中的内用很简单 adb connect %1
通过上述方法就能通过wifi和PC连接在一起了。注意:手机和PC机要在同一个局域网中。
相关文章推荐
- android pc通过wifi调试手机(无需USB连接)
- pc使用adb通过wifi连接到android手机
- 实现pc端通过usb获取到android手机上的短信、通讯录等信息
- PC通过WIFI连接Android设备,使用ADB
- 通过WIFI(不用数据线)连接Android手机调试
- Ubuntu下Android手机通过USB连接PC方法
- Uart2Socket:将PC的串口信息通过WiFi网络传输至安卓Android手机上
- WIFI 安卓Android系统手机通过USB连接电脑上网
- Android通过wifi连接手机(不需要root)
- Android手机与ide通过wifi连接
- Android杂谈--通过DDMS实现电脑与Android设备(如手机,平板)的网络连接、截图
- 【手机变身无线音箱-WIFI流媒体传输】--音乐在PC和手机间双向播放-详解Android DLNA使用-使用DLNA实现不同设备间媒体共享
- Android 通过代码设置、打开wifi热点及热点连接的实现代码
- 通过PC连接android手机
- 通过WiFi连接Android手机,进行ADB调试
- adb 通过wifi连接Android手机
- Ubuntu 11.04 下台式电脑通过已连接WIFI的Android手机上网
- Android_利用 adb 命令把电脑和 Android 手机通过 WIFI 进行连接,从此安装应用不需要数据线
- android 通过wifi 热点实现手机摄像头数据共享
- Ubuntu下Android如何将手机通过USB连接PC开发测试