[英]Android ACTIVITY RECOGNITION permission missing
I am targeting SDK 29, and activity transition API works perfectly on devices running 29 (ie Android 10).我的目标是 SDK 29,活动转换 API 在运行 29 的设备上完美运行(即 Android 10)。 According to the docs, if you are targeting SDK 29, but running on a lower SDK, the permission should be granted automatically.
根据文档,如果您的目标是 SDK 29,但在较低的 SDK 上运行,则应自动授予权限。
I have tried both, separately and together我都试过了,分开和一起
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>
I can't ask for the permission in a pop-up ( nothing happens).我不能在弹出窗口中请求许可(没有任何反应)。 When I try to register the Transitions API on phones < Andorid 10, I get the error:
当我尝试在 < Andorid 10 的手机上注册 Transitions API 时,出现错误:
com.google.android.gms.common.api.b: 10: SecurityException: Activity detection usage requires the ACTIVITY_RECOGNITION permission
If I set the target SDK to 28, everything works perfectly on all phones, but I need to target 29 for other reasons.如果我将目标 SDK 设置为 28,那么在所有手机上一切正常,但出于其他原因,我需要将目标设置为 29。 I am pulling my hair out.
我正在拔头发。 To be clear, it works perfectly on Android 10, just not below.
需要明确的是,它在 Android 10 上完美运行,只是不在下面。 Further code for clarification:
进一步说明代码:
public void askForActivityPermission(View v) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Log.d(TAG, "askForActivityPermission: q or greater");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACTIVITY_RECOGNITION}, PERMISSION_REQUEST_ACTIVITY_RECOGNITION);
} else {
Log.d(TAG, "askForActivityPermission: less than q");
moveNextStep();
}
}
@Override
public void onRequestPermissionsResult(
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
String permissionResult = "Request code: " + requestCode + ", Permissions: " +
Arrays.toString(permissions) + ", Results: " + Arrays.toString(grantResults);
Log.d(TAG, "onRequestPermissionsResult(): " + permissionResult);
if (requestCode == PERMISSION_REQUEST_ACTIVITY_RECOGNITION) {
Log.d(TAG, "onRequestPermissionsResult: permission granted?");
moveNextStep();
}
There were some updates in API Level 29. API 级别 29 中有一些更新。
1.Add the permission to the manifest file. 1.将权限添加到清单文件。
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
2.Check if the permission is granted: 2.检查是否授予权限:
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.ACTIVITY_RECOGNITION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
}
3.If permission isn't already granted, request the permission: 3.如果尚未授予权限,请请求权限:
ActivityCompat.requestPermissions(thisActivity,
arrayOf(Manifest.permission.ACTIVITY_RECOGNITION),
MY_PERMISSIONS_REQUEST_ACTIVITY_RECOGNITION);
Here are some useful docs.这里有一些有用的文档。
https://developer.android.com/about/versions/10/privacy/changes#physical-activity-recognition https://developer.android.com/about/versions/10/privacy/changes#physical-activity-recognition
https://developers.google.com/fit/android/authorization https://developers.google.com/fit/android/authorization
Ok, i have got it working, but it makes no sense, what so ever, like none.好的,我已经让它工作了,但它没有任何意义,什么都没有,就像没有一样。
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
The top one does not work, the bottom one does.上面那个不行,下面那个可以。 Can anyone tell me why?
谁能告诉我为什么?
I have tried all the suggested solutions, but none of them worked out.我已经尝试了所有建议的解决方案,但都没有成功。 I've tried all combinations of
com.google.android.gms.permission.ACTIVITY_RECOGNITION
and com.google.android.gms.permission.ACTIVITY_RECOGNITION
I've tried all combinations of
com.google.android.gms.permission.ACTIVITY_RECOGNITION
and com.google.android.gms.permission.ACTIVITY_RECOGNITION
with minSdkVersion 26
and targetSdkVersion 30
minSdkVersion 26
和targetSdkVersion 30
using an Android 9 (API 28) Wear OS emulator.使用 Android 9 (API 28) Wear OS 模拟器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.