首页 > 解决方案 > 如何编写导航到该功能并禁用它的脚本?

问题描述

我想禁用我们 android 设备的蜂窝网络设置中列出的功能。

我通过 ADB start 活动 com.android.phone/.MobileNetworkSettings adb shell input keyevent 20 & ADB shell input keyevent 23 尝试了以下操作

该代码运行良好,并且禁用了该功能,但是,我需要通过 MDM 将其应用于批量设备,并且它仅支持 JAVA 脚本。有没有办法编写一个导航到该功能并禁用它的脚本?

我们的设备操作系统是 android 6.01

标签: androidadb

解决方案


不是 MDM 解决方案,而是使用AndroidViewClient/culebra的普通 ADB 的更好替代方案

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (C) 2013-2019  Diego Torres Milano
Culebra v20.2.0
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
"""


import sys

from com.dtmilano.android.viewclient import ViewClient

_s = 5


device, serialno = ViewClient.connectToDeviceOrExit()

device.startActivity(component='com.android.phone/.MobileNetworkSettings')
vc = ViewClient(device, serialno)

vc.dump(window=-1)
mobile_data = vc.findViewWithTextOrRaise('Mobile data')
vc.findViewByIdOrRaise('android:id/switch_widget', mobile_data.parent).touch()
vc.sleep(_s)
vc.dump(window=-1)
vc.findViewWithTextOrRaise('OK').touch()

请注意,您可以使用Culebra GUI指向并单击设备表示来记录这样的脚本。此外,这可以同时在多个设备上运行。


推荐阅读