简体   繁体   中英

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?

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

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.

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

You need implement function:

   // SensorValueListener
   @Override
   public void onHeartRate(long timestamp, int rate, int accuracy) {
          ....
   }

and then use the function:

   onHeartRate(timestamp, rate, accuracy);

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