zoukankan      html  css  js  c++  java
  • adb获取手机设备蓝牙&热点&wifi状态并操作的笔记

    在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的端口发布全局广播,打开蓝牙,打开后会有弹窗询问允许,脚本中需要添加点击掉弹窗的方法
  • 相关阅读:
    JavaAndroid项目结构
    Python 常用系统模块整理
    Python 部分系统类的常用方法整理
    xpath语法笔记
    xml笔记
    Python 内置函数笔记
    剑指Offer-二叉搜索树的第k个结点
    Java中Set集合是如何实现添加元素保证不重复的?
    剑指Offer-链表中倒数第k个结点
    Leetcode#1.Two Sum(两数之和)
  • 原文地址:https://www.cnblogs.com/RuiRuia/p/13639863.html
Copyright © 2011-2022 走看看