Android是否支持Expo Pedometer? [英] Is Expo Pedometer supported on Android?

查看:57
本文介绍了Android是否支持Expo Pedometer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Expo在React Native中设置一个计步器应用程序,并在我真正的Samsung s10设备上测试代码.

I'm setting up a Pedometer app in React Native using Expo, testing the code on my real Samsung s10 device.

我正在使用世博计步器文档

但是,当我使用Pedometer.getStepCountAsync方法时,返回了一个错误"Android尚不支持获取日期范围的步骤计数."

However, when I use the Pedometer.getStepCountAsync method, I get returned an error "Getting step count for date range is not supported on Android yet."

我正在尝试制作一个计步器应用程序,该程序可以读取用户的操作步骤,然后将其显示给用户,但我无法获取操作步骤的数据.

I am trying to make a pedometer app that reads users steps, and then puts them into some visuals for the user but I can't get the steps data.

我的代码如下:到达错误=>行并返回上述错误. :(

My code is below: it reaches the error => line and returns the error mentioned above. :(

我已在Google Developer Console中启用了Fitness API,并且99%确信我拥有正确的凭据;因为我已经在同一应用程序中成功使用了Google登录名.

I've enabled the Fitness API in my Google Developer Console and am 99% sure I have the right credentials; as I have used the Google Login successfully in the same app.

const end = new Date();
    const start = new Date();
    start.setDate(end.getDate() - 1);
    Pedometer.getStepCountAsync(start, end).then(
      result => {
        this.setState({ pastStepCount: result.steps });

      },
      error => {
        this.setState({
          pastStepCount: "Could not get stepCount: " + error
        });
      }
    );

我想预期的结果是我从结果中得到了过去一天的用户操作,但是却收到了android不支持的错误信息.

I guess the expected result is that I get the user's steps from the past day in the result but instead I get the error that it is not supported on android.

推荐答案

我做了一些令人讨厌的解决方法,但它确实有效,我将expo 33添加为旧版npm依赖项,并且仅从那里使用了计步器模块,因为当前他们没有使用计步器模块在新的Expo unimodules上的android上实现了计步器功能

I did something nasty as a workaround but it worked I added expo 33 as a legacy npm dependency and use only the pedometer module from there because currently they didn't implemented the pedometer functionality on android on the new Expo unimodules

package.json

package.json

"expo": "^35.0.0",
 "expo-legacy": "npm:expo@33.0.0",

并像这样使用它

import {Pedometer} from 'expo-legacy'

令人惊讶地编译,apk大小仅增加了200kb

Surprisingly compiled and only increased 200kb the apk size

这篇关于Android是否支持Expo Pedometer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆