当前位置:   article > 正文

adb获取手机设备蓝牙&热点&wifi状态并操作的笔记_安卓设备判断热点已打开的命令

安卓设备判断热点已打开的命令

adb获取手机设备蓝牙&热点&wifi状态并操作的笔记
在Windows上查找字符串使用的是findstr,在linux上使用的是grep

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 方法112 $ adb shell svc wifi enable
13 #enable是打开,disable是关闭 如果output是killed,说明没有root权限,adb shell之后还要加su权限
14 方法215 $ 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 方法320 adb shell am broadcast -a io.appium.settings.wifi --es setstatus enable
21 #这个是调用了appium的端口发布全局广播,打开wifi,使用后会有弹窗询问是否允许,需要点击掉弹窗
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

热点

1 #获取状态
 2 
 3 在获取wifi状态中有提到
 4 
 5 
 6 
 7 #操作改变状态
 8 方法19 adb shell am start -n com.android.settings/.TetherSettings
10 adb shell input keyevent 20
11 adb shell input keyevent 66
12 #不一定适用所有机型,需要事先测试
13 方法214 #打开热点
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
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

蓝牙

 1 #获取状态
 2 $ adb shell settings get global bluetooth_on
 3 output是010代表关闭,1反之
 4 $ adb shell dumpsys bluetooth_manager | grep enabled
 5 output是true或者false,说明开启或关闭
 6 
 7 #改变操作状态
 8 方法19 $ adb shell settings put global bluetooth_on 1
10 #末尾设置为0代表关闭,1反之
11 方法212 $ adb shell svc bluetooth enable
13 #末尾设置为enable为开启,disable反之(这个方法输入命令后并不立即生效,重启设备才生效)
14 方法315 $ adb shell am start -a android.bluetooth.adapter.action.REQUEST_ENABLE
16 #目前只能从关闭状态转为开启状态,并且运行指令后会有弹窗提示是否开启蓝牙
17 方法418 adb shell am start -a android.settings.BLUETOOTH_SETTINGS
19 adb shell input keyevent 20
20 adb shell input keyevent 20
21 #同之前的启动方式,不一定适用所有机型
22 方法523 adb shell am broadcast -a io.appium.settings.bluetooth --es setstatus enable
24 #这个是调用了appium的端口发布全局广播,打开蓝牙,打开后会有弹窗询问允许,脚本中需要添加点击掉弹窗的方法
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/957849
推荐阅读
相关标签
  

闽ICP备14008679号