简体   繁体   English

Android Google Fit实时计步

[英]Android Google Fit real time step counting

I tried to count steps in real time using Google Fit SDK. 我尝试使用Google Fit SDK实时计算步数。

I used Sensor API to get step count changes in real time and it worked fine if I have Google Fit app installed on my phone. 我使用Sensor API实时更改步数,如果我在手机上安装了Google健身应用,则效果很好。

But when I uninstalled Google Fit app, it didn't worked. 但是当我卸载Google Fit应用程序时,它没有用。

Can anyone tell me what I did wrong and what should I do? 谁能告诉我我做错了什么,我该怎么办?

Thanks 谢谢

I found this answer , hope it helps you 我找到了这个答案 ,希望它可以帮到你

The Android 4.4 API Documentation states that the sensors are hardware dependent. Android 4.4 API文档指出传感器与硬件有关。

Both step sensors are hardware dependent (Nexus 5 is the first device to support them), so you should check for availability with hasSystemFeature(), using the FEATURE_SENSOR_STEP_DETECTOR and FEATURE_SENSOR_STEP_COUNTER constants. 两个步进传感器都是硬件相关的(Nexus 5是第一个支持它们的设备),因此您应该使用FEATURE_SENSOR_STEP_DETECTOR和FEATURE_SENSOR_STEP_COUNTER常量检查hasSystemFeature()的可用性。

You should check if the device has the functionality first. 您应该首先检查设备是否具有该功能。

PackageManager pm = getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER)) {
    // the awesome stuff here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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