'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?



Solution 1:[1]

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.

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Scott Driggers
Solution 2