【问题标题】:Android permissions not prompting the user in debugAndroid权限未在调试中提示用户
【发布时间】:2019-02-13 02:52:31
【问题描述】:

我是 Android 开发的新手,我正在开发一个需要 NFC 权限的应用。出于某种原因,该应用程序在打开时或当我将其靠近 NFC 标签或终端时不会提示用户。下面是我的 AndroidManifest.xml。谁能告诉我我在这里做错了什么?

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.NFC"/>
<uses-feature android:name="android.hardware.nfc.hce" android:required="true" />
<uses-feature android:name="android.hardware.nfc" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name=".MyHostApduService" android:exported="true"
        android:permission="android.permission.BIND_NFC_SERVICE">
        <intent-filter>
            <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
        </intent-filter>
        <meta-data android:name="android.nfc.cardemulation.host_apdu_service"
            android:resource="@xml/apduservice"/>
    </service>
</application>

【问题讨论】:

标签: android nfc android-permissions


【解决方案1】:

NFC 权限分类为PROTECTION_NORMAL(请参阅Permissions overview - Normal permissions)。因此,该权限不需要明确的用户同意,并且根本不应该有请求提示:

来自Permissions overview - Permission approval

如果您的应用在其清单中列出了正常权限(即不会对用户隐私或设备操作造成太大风险的权限),系统会自动将这些权限授予您的应用。

[...]

只有危险的权限需要用户同意。 [...]


顺便说一句。如果您的意思是您的应用根本不会触发 NFC 标签发现事件,那么原因是您的清单中似乎没有任何用于 NFC 标签发现的意图过滤器。例如,请参阅How to use NFC ACTIONS,了解如何注册标签发现。

【讨论】:

    猜你喜欢
    • 2021-07-28
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 2021-07-03
    • 2020-03-05
    • 1970-01-01
    • 2021-05-03
    • 2021-03-06
    相关资源
    最近更新 更多