3

I need to create app with optional NFC functionality. Can I get access to NFC without manifest permission (Android)? Or should I create two apps: an NFC version and one without it.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
user2944063
  • 65
  • 1
  • 4

2 Answers2

7

Updated as per finding of thorbear

The uses-feature element so that your application shows up in Google Play only for devices that have NFC hardware:

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

If your application uses NFC functionality, but that functionality is not crucial to your application, you can omit the uses-feature element and check for NFC avalailbility at runtime by checking to see if getDefaultAdapter() is null.


This is not possible without adding permission into manifest. And you do not required to create two apps for such case.

Read Requesting NFC Access in the Android Manifest for more details

But yes you have a way to say "My application uses NFC feature but optional". For this you need to add <uses-feature android:name="android.hardware.nfc" android:required="false" /> into manifest. So Google play can make your application available for all devices which have NFC or not have.

Note : If you do not add this <uses-feature .../> tag into manifest with android:required="false", Google Play will treat your application as "this application is only for devices which having NFC". And a device which does not have NFC feature, can not download your application from Google Play.


Here is manifest example

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

</manifest>

Read more about <uses-feature>

Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
  • Do you have any references for the note about `` needing to be declared explicitly as `required="false"`? According to the [linked documentation](https://developer.android.com/guide/topics/manifest/uses-feature-element.html#permissions) for `` NFC is not on the list of `Permissions that Imply Feature Requirements`. – Thorbear Feb 19 '18 at 09:46
  • @Thorbear Yes. Please read https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#manifest – Pankaj Kumar Feb 19 '18 at 09:57
  • Your reference seems to imply the opposite: `If your application uses NFC functionality, but that functionality is not crucial to your application, you can omit the uses-feature element [...]` – Thorbear Feb 19 '18 at 10:06
  • 1
    Done. PLease look now – Pankaj Kumar Feb 19 '18 at 10:17
2

You can't get access to NFC without adding the following permission to your manifest.

<uses-permission android:name="android.permission.NFC" />
Karim
  • 5,298
  • 3
  • 29
  • 35