Android:Google Fit找不到DataType.TYPE_LOCATION_SAMPLE的数据源 [英] Android: Google Fit not finding data sources for DataType.TYPE_LOCATION_SAMPLE

查看:51
本文介绍了Android:Google Fit找不到DataType.TYPE_LOCATION_SAMPLE的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些已经在生产环境中工作了几个月的代码,昨天突然在我所有的应用程序中停止了工作.我使用Google Fit通过Fitness.SensorClient API检索位置.安装时会向用户正确请求位置权限(通用的Android FINE_LOCATION权限以及将位置读取和存储到Google Fit中的权限).我通过以下方式创建健身选项:

I have some code that has worked for months in production which suddenly has stopped working yesterday in all my apps. I use Google Fit to retrieve locations via the Fitness.SensorClient API. Locations permissions are requested correctly to the user at installation time (both the generic Android FINE_LOCATION permission and the permission to read and store locations into Google Fit). I create the Fitness Option in this way:

setFitnessOptions(
            FitnessOptions.builder()
                    .addDataType(DataType.TYPE_LOCATION_SAMPLE, FitnessOptions.ACCESS_WRITE));

然后我以这种方式寻找数据源:

I then look for the DataSources in this way:

GoogleSignInAccount lastSignedAccount = GoogleSignIn.getAccountForExtension(context, getFitnessOptions());
    if (lastSignedAccount != null) {
        Fitness.getSensorsClient(context, lastSignedAccount)
                .findDataSources(
                        new DataSourcesRequest.Builder()
                                .setDataTypes(DataType.TYPE_LOCATION_SAMPLE)
                                .setDataSourceTypes(DataSource.TYPE_RAW)
                                .build())
                .addOnSuccessListener(
                        new OnSuccessListener<List<DataSource>>() {
                            @Override
                            public void onSuccess(List<DataSource> dataSources) {
                                for (DataSource dataSource : dataSources) {
                                    Log.i(TAG, "Data source found: " + dataSource.toString());
                                    Log.i(TAG, "Data Source type: " + dataSource.getDataType().getName());

...

OnSuccessListener中的参数dataSources的值是一个空列表.如果我尝试其他数据类型.setDataTypes(DataType.TYPE_STEP_COUNT_DELTA),则dataSources不是空列表.但是,DataType.TYPE_LOCATION_SAMPLE和DataType.TYPE_LOCATION_TRACK都不会返回任何数据源.

The value of the parameter dataSources in OnSuccessListener is an empty list. If I try other data types .setDataTypes(DataType.TYPE_STEP_COUNT_DELTA), dataSources is not an empty list. However neither DataType.TYPE_LOCATION_SAMPLE nor DataType.TYPE_LOCATION_TRACK return any data source.

我已经检查了Google服务的发行说明,似乎没有任何相关的更改.上面的代码似乎等同于Google提供的所有示例,例如这一个

I have checked the release notes of google services and nothing relevant seems to have changed. The code above seems to be equivalent to all the examples provided by Google, e.g. this one

有人知道为什么该代码突然停止工作了吗?谢谢

Does anyone have an idea of why suddenly that code has stopped working? Thanks

更新:我已经验证了它不适用于Android 6、7、8或9.

UPDATE: I have verified that it does not work with Android 6, 7, 8, or 9.

推荐答案

我找到了解决方案.在代码的另一部分中,我正在使用GoogleSignIn.getLastSignedInAccount进行订阅.显然,这可能会导致不匹配,并且不会返回位置.更改对GoogleSignIn.getAccountForExtension的订阅即可解决该问题

I have found the solution. In another part of my code I was subscribing using GoogleSignIn.getLastSignedInAccount. Apparently this may cause a mismatch and the locations are not returned. Changing the subscription to GoogleSignIn.getAccountForExtension solved the issue

这篇关于Android:Google Fit找不到DataType.TYPE_LOCATION_SAMPLE的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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