简体   繁体   English

带有葫芦的真实Android设备上的飞行模式模拟

[英]Airplane mode simulation on a real Android device with calabash-android

In part of my testing I'm checking if my app can handle returning from airplane mode to normal mode. 在测试的一部分中,我正在检查我的应用程序是否可以处理从飞行模式返回到正常模式的操作。

Looking for a process that enable/disable airplane mode on real Android device. 寻找一个在真实的Android设备上启用/禁用飞行模式的过程。

All I found is how to enable/disable WiFi and data on simulator here - Best way to turn airplane mode on and off with Calabash . 我发现的全部是如何在此处启用/禁用模拟器上的WiFi和数据- 用Calabash打开和关闭飞行模式的最佳方法 Tried to run those commands on my real device (LG G3 – Android 5.0) and nothing happened. 试图在我的真实设备(LG G3 – Android 5.0)上运行这些命令,但没有任何反应。

Looking on my services list on my device ( adb shell service list ) but cannot find airplane. 在设备上查看我的服务列表( adb shell service list ),但找不到飞机。

I understand that changing to airplane mode is disabling the data/WiFi/Bluetooth/GPS 我了解更改为飞行模式会禁用数据/ WiFi /蓝牙/ GPS

Is there a way to enable airplane mode on real device? 有没有办法在真实设备上启用飞行模式? Or even just the data/WiFi (enough for my testing)? 甚至只是数据/ WiFi(足以进行我的测试)?

If you have no luck with adb commands, You can enable/disable airplane mode with adb shell input gestures. 如果您对adb命令没有运气,则可以使用adb shell input手势启用/禁用飞行模式。

  adb -s <DeviceSerialNumber> shell input touchscreen swipe x1 y1 x2 y2 time

Where x1,x2,y1,x2 is swipe start and end coordinates and time is time in ms to perform the gesture. 其中x1,x2,y1,x2是滑动开始和结束坐标,而time是以毫秒为单位执行手势的时间。

By combining these, you can perform anything on screen. 通过组合这些,您可以在屏幕上执行任何操作。

For example airplane mode. 例如飞机模式。

  • Get screen resolution of your device 获取设备的屏幕分辨率
  • Swipe notification bar from the top 从顶部滑动通知栏
  • Touch airplane mode 触控飞行模式
  • And press back button 然后按返回按钮

Not the best way to do that, but comes handy sometimes. 这不是最好的方法,但有时会派上用场。

Another way around that 另一种解决方法

https://developer.android.com/reference/android/provider/Settings.Global.html https://developer.android.com/reference/android/provider/Settings.Global.html

Check the settings you interested in, and use adb shell settings put 检查您感兴趣的设置,并使用adb shell settings put

For example: 例如:

  adb -s <DeviceSerialNumber> shell settings put global airplane_mode_on 1

A question about events: 有关事件的问题:

How to use ADB to send touch events to device using sendevent command? 如何使用ADB通过sendevent命令将触摸事件发送到设备?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM