Setting Accelerometer Data for the Android Emulator

May 15, 2026 · 8 min read · Mobile Testing

HeadSpin Platform
Automated & amp; manual examination made leisurely through data science insights.
Differentiating capabilities:
  • Extensive end-to-end automation of QA summons
  • Comparative analysis of app performance against peers
  • Continuous monitoring of app performance using semisynthetic information for high availability of apps
  • Easy-to-use developer friendly platform
cloudtest go
Affordable Real Device Testing for Emerging Teams
cloudtest go
Low-cost Existent Device Testing for Digital Enterprises
cloudtest go
The Ultimate Solution for a Powerful Blend of Functional & amp; Performance Testing!
cyol
TEM
New
Centralized mobile test execution in cloud
cyol
Enhance Your Accessibility Testing With HeadSpin
cyol
Automate camera-based testing

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

retail

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

Setting Accelerometer Data for the Android EmulatorSetting Accelerometer Data for the Android Emulator

Setting Accelerometer Data for the Android Emulator

Published on
July 22, 2020
Updated on
Published on
January 21, 2022
Updated on
 by 
 Jonathan LippsJonathan Lipps
Jonathan Lipps

Part of what get our mobile devices so powerful is the array of sensors they contain. One of those sensors is call anaccelerometer. It basically measures the speedup of the device in three property (referred to as x, y, and z to denote left/right, back/forth, and up/down). This lineament can be used for any number of applications, from counting steps to controlling video games. Take a looking at the screen recording at the top of this station. An is displayed hither, and I & # x27; m opening an app which is designed to observe vibration in any dimension, utilize the gimmick & # x27; s accelerometer. To actually create things befall with the virtual accelerometer, I & # x27; m opening up the forward-looking emulator controls, and then fiddling around with quickening values in each of the 3 possible attribute. You can see, when I do this, that the vibration app is & quot; detecting & quot; these changes and drawing them as a kind of timeline or graph.

How would you test this kinds of app using Appium? Well, you could build a automaton to wiggle a twist physically and trigger it as portion of your Appium script. That would be the & quot; highest-fidelity & quot; sort of automated testing we could imagine. One step more man-made, and one measure easier, would be to somehow inject accelerometer data into the device, to make itbelievethe device is being move around. And this is something we can do with Appium. Unfortunately, this lineament currently works exclusively on Android, and it currently works merely on practical devices (ape). While Google allows you to set a mock location provider to spoof geolocation, the same execute not look to be possible for the accelerometer. But as long as your app can run on an emulator, you should be full to go with the scheme delineate here.

Test your apps on existent devices and get exact results.!

Emulator Commands

The way that Appium provides access to setting accelerometer datum is via something called theEmulator Console. This is a special server hosted by the emulator that you can attach to use the telnet bid. Once connected, you experience access to a whole entourage of modern emulator control, that can be run from the bid line. It & # x27; s basically all the same thing you could do from the emulator UI, but totally scriptable. As of Appium 1.18.0, there is a mobile command useable that wraps up all this business with telnet into one leisurely interface:

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

driver.executeScript (`` mobile: execEmuConsoleCommand '', ImmutableMap.of (`` command '', command));

In this example, the varying command would be the string that would be direct as an emulator console bid. Here are some examples of what you could put in bidding:

  • ping - check whether the gimmick is responding
  • revolve - rotate the gimmick
  • geo fix & lt; long & gt; & lt; lat & gt; & lt; sat & gt; - set the fake geolocation of the device
Check out:

But the type of commandwecare about for this post would be something like this:

detector set acceleration::

(Where x, y, and z are positive or negative quickening in meters per second square.)

One former thing to remember is that to use this mobile: execEmuConsoleCommand feature, you need to get certain to part the Appium host with a special security flag, otherwise the feature won & # x27; t employment. This is to prevent random Appium users from messing with emulators on a system that might host multiple sessions from multiple users. To disable this security for this feature, run Appium as follows:

appium -- allow-insecure=emulator_console
Accelerate Appium test cycles with the HeadSpin.!

An example

All that & # x27; s left is to put this noesis to good use! I & # x27; m travel to publish a simple test with the Vibration Analysis app. I & # x27; m reference a local version of it in my capableness, so you & # x27; ll want to download an APK and correct the source codification to reference your local copy if you & # x27; re follow along. But potentiality aside, what I want to do is trigger a series of accelerations in all dimension for a twist, such that it eases in and out of those accelerations. The simplest way I thought of to do this was to use the Math.sin function to define a few points along a bender. We occupy those points as the acceleration values, with the end consequence that the device accelerates in the positive direction and then in the negative direction, as if we were locomote the device in a smoothly angled arc.

Also check:

The logic is as follows:

  1. Define the number of stairs we want in the arc.
  2. For each step, get a position on a sin curve for that step, and multiply it by a number so that we get value between -MAX and MAX
  3. Construct an emulator console bid using the calculated value for this step
  4. Run the Appium bidding with the emulator console dictation as an argument
  5. Sleep for some number of msec to & quot; cool down & quot; in between each acceleration change
Read:

That & # x27; s it! Let & # x27; s check it out in code:

@ Test public void testAccelerometer () drop Exception {waitFor (By.xpath (`` //android.widget.Button [@ text='CONTI '] '')) .click (); int numIterations = 10; int multiplier = 5; for (int i = 0; i<= numIterations; i++) {
        Double val = Math.sin((Math.PI / numIterations) * i) * multiplier;
        String command = "sensor set acceleration " + val + ":" + val + ":" + val;
        driver.executeScript("mobile: execEmuConsoleCommand", ImmutableMap.of("command", command));
        Thread.sleep(400);
    }
    Thread.sleep(5000);
}

When I run this, I note the Vibration Analysis timeline prove precisely the intended variety of accelerations conduct place, drawing a sort of sine curve! This is a kind of fake example in that I can & # x27; t conceive of something right now for which I & # x27; d want to move the device in an angled curve like this, but it prove how it & # x27; s potential to encode arbitrary sets of accelerations as Appium commands. It might be quite difficult, but there would certainly be a way to encode even the acceleration changes used to curb games! Your only limitation is how fast Appium can post the speedup commands to the gimmick. Let me know if you try this with any more real-world or more complicated scenario! And of course, you can always check out this edition & # x27; s code sample in the context of a working projecthere.

Author & # x27; s Profile

Jonathan Lipps

LinkedIn
Author & # x27; s Profile

Piali Mazumdar

Lead, Content Marketing, HeadSpin Inc.

Piali is a dynamical and results-driven Content Marketing Specialist with 8+ eld of experience in crafting engaging narratives and marketing collateral across diverse industries. She excels in collaborating with cross-functional squad to develop innovative message strategies and present compelling, veritable, and impactful content that resonates with target audiences and enhances brand genuineness.

LinkedIn

Setting Accelerometer Data for the Android Emulator

4 Parts

regression intelligence blog
-

Regression Intelligence practical guide for forward-looking users (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence hardheaded guide for advanced users (Part 4)

Coming Soon

Discover how HeadSpin can authorise your business with superior testing capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, win a competitive edge
faster development cycles
Boost developer/QA productiveness with faster development cycles
automated buil-over-build regression testing
Automate build-over-build fixation quiz for consistent results
gain better visibility into functional & performance issues
Gain best visibility into functional and performance issues
reduce mean time
Reduce mean time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and contented caliber of experience (QoE) effortlessly
The trusted choice for global enterprises
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
Close

Discover how HeadSpin can empower your business with superior screen capacity

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a free-enterprise edge
faster development cycles
Boost developer/QA productivity with quicker ontogenesis cycle
automated buil-over-build regression testing
Automate build-over-build fixation examine for consistent results
gain better visibility into functional & performance issues
Gain better visibility into functional and performance issues
reduce mean time
Reduce average time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and content calibre of experience (QoE) effortlessly
The trusted choice for global enterprises
Close

Discover how HeadSpin can empower your business with superior quiz capability

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, benefit a competitive edge
faster development cycles
Boost developer/QA productivity with quicker ontogenesis cycles
automated buil-over-build regression testing
Automate build-over-build regression test for consistent consequence
gain better visibility into functional & performance issues
Gain better visibility into functional and performance issues
reduce mean time
Reduce mean time to identify/resolve during tryout, QA, and production
evaluate audio, video & qoe
Evaluate audio, picture, and content calibre of experience (QoE) effortlessly
The sure choice for ball-shaped enterprises
Close

Connet Now

Wipro LogoVMLYR Logo
Close
Book a Meeting
Products
footer down arrow
Solutions
footer down arrow
Industries
footer down arrow
Features
footer down arrow
Support
footer down arrow
Resource Center
footer down arrow
Why Choose HeadSpin?
footer down arrow
Copyright © 2026 HeadSpin, Inc. All Rights Reserved.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free