有寫特殊Android設備只有一個USB口,當掛載U盤之後就無法連接USB實時進行調試了。這兒時候如果設備可以開啓WiFi,那就可以用WiFi進行調試;
要開啓網絡調試,執行下面指令即可:
"setprop service.adb.tcp.port 5555",// 設置監聽的端口,端口可以自定義,如5554,5555是默認的
"stop adbd",// 關閉adbd
"start adbd"// 重新啓動adbd
但執行上述指令必須要有root權限,既先要執行:
su//切換到root用戶;
上面完成之後就可以用adb命令:
adb connect 192.168.1.xx//Android設備的ip地址;
上述在設備連接電腦執行cmd時在
"stop adbd",// 關閉adbd
這一步會有問題,執行之後USB就斷開了,無法執行接下來的打開指令;
那怎麼辦呢?
想到直接做一個apk,安裝在手機上執行,於是就有了下面的apk:
public void excuteStartShell() {
String[] commands = new String[] {
"setprop service.adb.tcp.port 5555",// 設置監聽的端口,端口可以自定義,如5554,5555是默認的
"stop adbd",// 關閉adbd
"start adbd",// 重新啓動adbd
};
try {
List<String> temp = RootTools.sendShell(commands, 10, 3000);
for (int i = 0; i < temp.size(); i++) {
Log.i(TAG, "__This is result from root:__" + temp.get(i));
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void excuteStopShell() {
String[] commands = new String[] {
"setprop service.adb.tcp.port -1",// 設置監聽的端口,端口可以自定義,如5554,5555是默認的
"stop adbd",// 關閉adbd
"start adbd",// 重新啓動adbd
};
try {
List<String> temp = RootTools.sendShell(commands, 10, 3000);
for (int i = 0; i < temp.size(); i++) {
Log.i(TAG, "__This is result from root:__" + temp.get(i));
}
} catch (Exception e) {
e.printStackTrace();
}
}
附apk下載文件,需要源碼的留言;