Pierpaolo Ercoli
Pierpaolo Ercoli

Reputation: 1064

How can I simulate datas from Heart Rate sensor on Android Wear Emulator?

As the title, how can I do to "simulate" some values from the emulated heart rate sensor from the emulator? Is this possible on the official emulator or do you know some alternative emulators that do this?

Upvotes: 2

Views: 3071

Answers (3)

Victor Eronmosele
Victor Eronmosele

Reputation: 7716

LOCATE HEART RATE VIRTUAL SENSOR

If you can not find the heart rate sensor under "Additional Sensors" as described in Scott's answer, you need to add this line below to your AVD's config.ini file.

hw.sensors.heart_rate=yes

For MacOS, the config.ini file can be found at this path:

/Users/{your user name}/.android/avd/{your AVD name}.avd/config.ini

INCLUDE PERMISSION:

You also need to request the android.permission.BODY_SENSORS.

This sensor requires permission android.permission.BODY_SENSORS. It will not be returned by SensorManager.getSensorsList nor SensorManager.getDefaultSensor if the application doesn't have this permission.

Source: Android Heart Rate Sensor documentation.

You can do that using the following methods:

public void permissionRequest(){
    if (checkSelfPermission(Manifest.permission.BODY_SENSORS)
            != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(
                new String[]{Manifest.permission.BODY_SENSORS},
                MY_PERMISSIONS_REQUEST_BODY_SENSOR);
    }
    else{
        Log.d(TAG,"ALREADY GRANTED");
    } 
}

OR you can enable it from Settings>Apps>YOUR_APP>Permissions>Sensor

Source: https://gist.github.com/mjohnsullivan/557c2f19ba177312b1d7?permalink_comment_id=2615046#gistcomment-2615046

Upvotes: 2

Scott Driggers
Scott Driggers

Reputation: 369

Updating this answer for 2021. With the current emulator, you can click "..." in the emulator's menu and navigate to "Virtual Sensors -> Additional Sensors". Here you can move the heart rate slider to control it.

Upvotes: 5

Evgeniy Strepetov
Evgeniy Strepetov

Reputation: 684

No, you can't, android emulator can't simulate any sensors. Android Wear emulators can't do it too

Upvotes: 2

Related Questions