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

讓客戶(hù)滿(mǎn)意是我們工作的目標(biāo),不斷超越客戶(hù)的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶(hù),將通過(guò)不懈努力成為客戶(hù)在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)、雅安服務(wù)器托管、營(yíng)銷(xiāo)軟件、網(wǎng)站建設(shè)、延慶網(wǎng)站維護(hù)、網(wǎng)站推廣。
1.在程序中通過(guò)
- Runtime.getRuntime().exec("su");
獲得手機(jī)root權(quán)限(手機(jī)必須是root之后的)。
2.重新啟動(dòng)adbd
- exec("stop adbd");
- exec("start adbd");
3.與PC建立連接(我是通過(guò)bat文件進(jìn)程處理的)
- /**
- * 手機(jī)連接wifi.
- *
- * @param host 手機(jī)ip:端口號(hào)。例如: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文件中的內(nèi)用很簡(jiǎn)單 adb connect %1
通過(guò)上述方法就能通過(guò)wifi和PC連接在一起了。注意:手機(jī)和PC機(jī)要在同一個(gè)局域網(wǎng)中。
新聞標(biāo)題:實(shí)現(xiàn)Android手機(jī)通過(guò)WIFI和PC連接
分享URL:http://fisionsoft.com.cn/article/dpchesp.html


咨詢(xún)
建站咨詢(xún)
