gpt4 book ai didi

android - 为什么 `hasEnrolledFingerprints` 给出错误,它只需要在我的 fragment 中获得许可,而不需要在 Google 示例中的 Activity 中获得许可?

转载 作者:可可西里 更新时间:2023-11-01 19:07:40 25 4
gpt4 key购买 nike

我正在尝试在我的应用程序中(特别是在我的 fragment 中)实现 Google 的指纹 API。谷歌给出了一个例子,但它是在 Activity 中实现的 here .

我的具体问题是下面的代码检查是否已经注册了指纹,它给我一个错误(下面的屏幕截图):

问题 --> 我需要做哪些更改才能使其在我的 Fragment 中运行(与 Google 那样的 Activity 相反)?

if (!mFingerprintManager.hasEnrolledFingerprints()) {
purchaseButton.setEnabled(false);
// This happens when no fingerprints are registered.
Toast.makeText(getActivity(),
"Go to 'Settings -> Security -> Fingerprint' and register at least one fingerprint",
Toast.LENGTH_LONG).show();
return;
}

enter image description here

最佳答案

Android 6.0 必须在运行时“请求”许可。 https://developer.android.com/training/permissions/requesting.html

Dangerous permissions can give the app access to the user's confidential data. If your app lists a normal permission in its manifest, the system grants the permission automatically. If you list a dangerous permission, the user has to explicitly give approval to your app.

即使你有<uses-permission android:name="android.permission.USE_FINGERPRINT"/>在你的 list 中,我的理解是你必须征求许可。所以看起来错误是因为您的应用没有使用指纹管理器的运行时权限。

(只有 90% 的把握,因为我现在坚持使用 5.0,抱歉)


更新:http://developer.android.com/reference/android/Manifest.permission.html#USE_FINGERPRINT

public static final String USE_FINGERPRINT ---------- Added in API level 23

Allows an app to use fingerprint hardware.

Protection level: normal

看来您在运行时不需要此权限。

1) 您的 list 中是否有权限?

2) 您应该将以下代码放入您的代码中,以检查权限是否因某种原因被撤销/未授予。

if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.USE_FINGERPRINT) // this might need massaged to 'android.permission.USE_FINGERPRINT'
!= PackageManager.PERMISSION_GRANTED) {
Log.d ("TEST", "You don't have permission");
}

(或类似的东西)就像来自 https://developer.android.com/training/permissions/requesting.html 的例子

关于android - 为什么 `hasEnrolledFingerprints` 给出错误,它只需要在我的 fragment 中获得许可,而不需要在 Google 示例中的 Activity 中获得许可?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34476043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com