Can I get access to NFC without manifest permission in android?

我只是一个虾纸丫 提交于 2019-12-10 18:14:53

问题


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.


回答1:


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>




回答2:


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

<uses-permission android:name="android.permission.NFC" />


来源:https://stackoverflow.com/questions/30391355/can-i-get-access-to-nfc-without-manifest-permission-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!