简体   繁体   中英

How can I shake an Android Emulator device in Android Studio 3.0?

I need to test a newly developed app on multiple Android device emulators through Android Studio.

This app has multiple environments wherein this is hosted, like, qa, UAT, Production. I can change the environment through a screen that comes only after shaking a real device.

Unfortunately, Android Studio 3 does not give a direct option to shake the device. How can I achieve this shake action in the emulator?

Try

Ctrl + m for windows

⌘ + m for Mac OS-X

Ok Try this ... Goto Setting->Virtual Sensors in emulator menu

Click on Move checkbox

Now try moving XYZ seekbar

You can use this code snap to detect shake ShakeDetectionDemo

模拟器

移动模拟器

Shake with one command line:

{ echo "auth $(cat ~/.emulator_console_auth_token)"; echo "sensor set acceleration 0:0:0"; sleep 1; echo "sensor set acceleration 100:100:100"; sleep 1; } | telnet localhost 5554
  • 5554 - port of the emulator (on top of window).
  • ~/.emulator_console_auth_token - auth-token of the emulator (to access sensor command).

Demonstration video: https://youtu.be/_vYvx6iqZ1I

要从命令行 (CLI) 模拟 1 秒摇动,您可以执行以下操作:

adb emu sensor set acceleration 100:100:100; sleep 1; adb emu sensor set acceleration 0:0:0

For those that run into this issue with a Expo / React Native app, Ctrl+m will not work with Production mode turned on. If that's your case, you'd need to set it back to Development mode.

Not sure if there's an alternative "mode" for native development.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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