在Windows上查找字符串使用的是findstr,在linux上使用的是grep
wifi
1 #獲取狀態 2 3 $ adb shell ps | findstr wifi 4 #output中出現wpa_supplicant說明wifi處於開啟狀態,如果出現hostapd說明熱點處於開啟狀態 5 $ adb shell dumpsys wifi | findstr curState 6 #output中出現Active說明wifi處於開啟狀態 7 8 9 10 #操作改變狀態 11 方法1: 12 $ adb shell svc wifi enable 13 #enable是打開,disable是關閉 如果output是killed,說明沒有root權限,adb shell之后還要加su權限
14 方法2:
15 $ adb shell am start -n com.android.settings/.wifi.WifiSettings 或者 adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings
16 $ adb shell input keyevent 20
17 $ adb shell input keyevent 23
18 #不一定適用所有機型,需要事先測試
19 方法3:
20 adb shell am broadcast -a io.appium.settings.wifi --es setstatus enable
21 #這個是調用了appium的端口發布全局廣播,打開wifi,使用后會有彈窗詢問是否允許,需要點擊掉彈窗
熱點
1 #獲取狀態 2 3 在獲取wifi狀態中有提到 4 5 6 7 #操作改變狀態 8 方法1: 9 adb shell am start -n com.android.settings/.TetherSettings 10 adb shell input keyevent 20 11 adb shell input keyevent 66 12 #不一定適用所有機型,需要事先測試
13 方法2:
14 #打開熱點
15 adb shell service call connectivity 24 i32 0
16 #關閉熱點
17 adb shell service call connectivity 25 i32 0
18 此操作需要root權限 ; 末尾的0是傳遞的參數,0是wifi網絡共享,1是usb網絡共享,2是藍牙網絡共享
19 更多信息可參考:https://android.stackexchange.com/questions/111226/using-adb-shell-how-i-can-disable-hotspot-tethering-on-lollipop-nexus-5
藍牙
1 #獲取狀態 2 $ adb shell settings get global bluetooth_on 3 output是0或1,0代表關閉,1反之 4 $ adb shell dumpsys bluetooth_manager | grep enabled 5 output是true或者false,說明開啟或關閉 6 7 #改變操作狀態 8 方法1: 9 $ adb shell settings put global bluetooth_on 1 10 #末尾設置為0代表關閉,1反之 11 方法2: 12 $ adb shell svc bluetooth enable 13 #末尾設置為enable為開啟,disable反之(這個方法輸入命令后並不立即生效,重啟設備才生效) 14 方法3: 15 $ adb shell am start -a android.bluetooth.adapter.action.REQUEST_ENABLE 16 #目前只能從關閉狀態轉為開啟狀態,並且運行指令后會有彈窗提示是否開啟藍牙 17 方法4: 18 adb shell am start -a android.settings.BLUETOOTH_SETTINGS 19 adb shell input keyevent 20 20 adb shell input keyevent 20 21 #同之前的啟動方式,不一定適用所有機型
22 方法5:
23 adb shell am broadcast -a io.appium.settings.bluetooth --es setstatus enable
24 #這個是調用了appium的端口發布全局廣播,打開藍牙,打開后會有彈窗詢問允許,腳本中需要添加點擊掉彈窗的方法