简体   繁体   中英

Android permissions not prompting the user in debug

I'm new to Android development and I'm working on an app that will require NFC permissions. For some reason, the app is not prompting the user when it opens or when I hold it near an NFC tag or terminal. Below is my AndroidManifest.xml. Can anyone tell me what I'm doing wrong here?

<?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>

The NFC permission is classified as PROTECTION_NORMAL (see Permissions overview - Normal permissions ). Consequently, that permission does not require explicit user consent and there should not be a request prompt at all:

From Permissions overview - Permission approval :

If your app lists normal permissions in its manifest (that is, permissions that don't pose much risk to the user's privacy or the device's operation), the system automatically grants those permissions to your app.

[...]

Only dangerous permissions require user agreement. [...]


Btw. if you meant that your app simply does not trigger for NFC tag discovery events, the reason for this is that you don't seem to have any intent filter for NFC tag discovery in your manifest. See, eg, How to use NFC ACTIONS on how to register for tag discovery.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM