在Android 10/Q(SDK 29)上运行的Android ACTIVITY_RECOGNITION权限SDK 28 [英] Android ACTIVITY_RECOGNITION Permission SDK 28 running on Android 10/Q (SDK 29)

查看:599
本文介绍了在Android 10/Q(SDK 29)上运行的Android ACTIVITY_RECOGNITION权限SDK 28的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Android应用针对SDK 28,并连接到Google Fit以上传数据和读取其他数据.该应用程序使用HistoryAPI读取com.google.step_count.delta数据.

My Android app targets SDK 28 and connects to Google Fit to upload data and read some other data. The app uses the HistoryAPI to read com.google.step_count.delta data.

本文档声称,如果该应用程序定位于SDK 28但在SDK 29上运行,则"com.google.android.gms.permission.ACTIVITY_RECOGNITION权限将转换为预先授予的运行时权限":

This documentation claims that "com.google.android.gms.permission.ACTIVITY_RECOGNITION permission is converted into a pre-granted runtime permission" if the app targets SDK 28 but runs on SDK 29: https://developers.google.com/fit/android/authorization#android_permissions

我已经按照文档说明的那样添加到应用程序清单中.

I have added to the app's manifest like the documentation says to do.

当此Android应用在运行Android 10(SDK 29)的设备上并且用户首次连接到Google Fit时,我收到一条日志,内容为:

When this Android app is on a device running Android 10 (SDK 29) and the user connects to Google Fit for the first time, I get a log saying:

There was a problem subscribing.com.google.android.gms.common.api.ApiException: 10: SecurityException: com.google.step_count.delta requires android.permission.ACTIVITY_RECOGNITION

然而,文档声称它将被转换为预先授予的运行时权限.

Yet the documentation claims that this will be converted into a pre-granted runtime permission.

团队还没有准备好将应用程序的目标SDK迁移到29,那么我们如何才能继续获取com.google.step_count.delta数据而不会出现此错误?

The team is not ready to migrate the app's target SDK to 29 just yet, so how can we continue to get com.google.step_count.delta data without this error?

我假设此日志意味着它实际上没有连接,因为没有日志语句显示:

I am assuming that this log means it didn't actually connect as there was no log statement that said:

Successfully subscribed to com.google.step_count.delta

推荐答案

已解决:在App Api 28级以上

Solved: In App Api Level 28 +

<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>

应用程序应检查是否已授予权限:

The app should check if the permission is granted already:

if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.ACTIVITY_RECOGNITION)
          != PackageManager.PERMISSION_GRANTED) {
      // Permission is not granted
}

要请求许可:

ActivityCompat.requestPermissions(thisActivity,
                  arrayOf(Manifest.permission.ACTIVITY_RECOGNITION),
                  MY_PERMISSIONS_REQUEST_ACTIVITY_RECOGNITION);

详细了解有关请求Android运行时权限的信息.

Learn more about requesting Android runtime permissions.

如果您的应用定位到SDK级别28或更低,则必须在其清单文件中指定com.google.android.gms.permission.ACTIVITY_RECOGNITION权限.

If your app targets SDK level 28 or below, it must specify the com.google.android.gms.permission.ACTIVITY_RECOGNITION permission in its manifest file.

这篇关于在Android 10/Q(SDK 29)上运行的Android ACTIVITY_RECOGNITION权限SDK 28的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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