自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

實現(xiàn)Android手機(jī)通過WIFI和PC連接

移動開發(fā) Android
大家如果手邊沒有路由器,只有無線網(wǎng)卡,一樣可以使用手機(jī)自帶的Wifi上網(wǎng),前提電腦必須具備有線網(wǎng)絡(luò),并且無線網(wǎng)卡驅(qū)動已經(jīng)正常安裝!Let's go!其它Andro手機(jī)應(yīng)該也可以使用。

最近一段事件一直在研究如何用wifi和PC連接,但是在網(wǎng)上找了很久,也看過很多例子。都沒有成功。無奈只好自己研究。***自己寫了一個小Demo。分享一下。[[69567]]

1.在程序中通過

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

獲得手機(jī)root權(quán)限(手機(jī)必須是root之后的)。

2.重新啟動adbd

  1. exec("stop adbd"); 
  2. exec("start adbd"); 

3.與PC建立連接(我是通過bat文件進(jìn)程處理的)

  1. /** 
  2.          * 手機(jī)連接wifi. 
  3.          * 
  4.          * @param host 手機(jī)ip:端口號。例如:192.168.10.124:8888 
  5.          */ 
  6.         public int connectWifi(String host) { 
  7.             String cmd = ParseProperties.getProperties("dir") 
  8.                     + "bin/ConnectWifi.bat " + host; 
  9.             BufferedReader reader = null
  10.             int retcode = 0
  11.             try { 
  12.                 Process process = Runtime.getRuntime().exec(cmd); 
  13.       
  14.                 reader = new BufferedReader(new InputStreamReader( 
  15.                         process.getInputStream())); 
  16.                 @SuppressWarnings("unused") 
  17.                 String line = null
  18.                 String returnLine = null
  19.                 System.out.println("*****************************"); 
  20.                 while ((line = reader.readLine()) != null) { 
  21.                     if (line != null) 
  22.                         returnLine = line
  23.                     System.out.println(line); 
  24.                 } 
  25.                 if (returnLine.trim().startsWith("connected to")) { 
  26.                     retcode = SUCCESS
  27.                 } else if (returnLine.trim().startsWith("already connected to")) { 
  28.                     retcode = SUCCESS
  29.                 } else { 
  30.                     retcode = FAILE
  31.                 } 
  32.                 System.out.println("*****************************"); 
  33.             } catch (IOException e) { 
  34.                 e.printStackTrace(); 
  35.                 retcode = FAILE
  36.             } finally { 
  37.                 if (reader != null) { 
  38.                     try { 
  39.                         reader.close(); 
  40.                     } catch (Exception e) { 
  41.                         e.printStackTrace(); 
  42.                     } 
  43.                 } 
  44.             } 
  45.             if (retcode == 0) { 
  46.                 retcode = FAILE
  47.             } 
  48.             return retcode; 
  49.         } 

bat文件

bat文件中的內(nèi)用很簡單 adb connect %1

通過上述方法就能通過wifi和PC連接在一起了。注意:手機(jī)和PC機(jī)要在同一個局域網(wǎng)中。

責(zé)任編輯:閆佳明 來源: oschina
相關(guān)推薦

2020-08-28 10:01:08

AndroidPC手機(jī)屏幕

2018-01-24 16:30:43

Linux命令Wifi

2023-06-12 15:35:04

綜合布線光纖以太網(wǎng)

2019-11-08 10:00:09

Windows手機(jī)應(yīng)用程序

2022-09-11 19:55:46

MAC 地址WiFi 地址

2021-04-30 12:17:18

ChromiumEdge瀏覽器

2009-12-16 10:23:04

家庭無線路由設(shè)置

2021-11-08 05:33:25

PC安卓手機(jī)投屏

2013-01-24 11:09:57

索尼存儲NFC

2021-09-14 09:50:29

物聯(lián)網(wǎng)超連接IOT

2011-12-15 09:58:38

Wifi私有云

2011-12-15 13:14:08

免費wifi私有云

2012-02-22 11:08:07

UbuntuAndroid

2014-10-29 10:38:36

手機(jī)PC協(xié)議

2010-05-18 10:07:23

桌面PC云計算

2023-03-29 10:03:36

2020-11-02 11:56:57

鴻蒙 WiFi操作

2013-09-16 15:00:15

2019-12-09 16:52:31

華為鴻蒙

2010-08-16 14:17:46

無線路由
點贊
收藏

51CTO技術(shù)棧公眾號