How to give condition to Android application to run only on NFC enabled device?

自闭症网瘾萝莉.ら 提交于 2019-12-12 10:16:24

问题


I developing a application which read the NFC Tag details.. In that application i want to give the condition to run only in NFC available devices..

Thanks in Advance...


回答1:


If you include this in your manifest your app will only be able to run on devices that have NFC:

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

NfcAdapter.getDefaultAdapter(this) can also return null on a device which has NFC, but the NFC functionality is unavailable for some reason in that case.




回答2:


If you're uploading it to the Play Store, then you can choose which devices can download the app, so keep that in mind.

This is how you check to see if the device can use NFC.

NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (mNfcAdapter == null) {
            Toast.makeText(this,"NFC is not available on this device.", LENGTH_LONG).show();
        }



回答3:


Change your manifest to require the NFC permission as specified in the documentation.




回答4:


Include this into your AndroidManifest.xml:

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

Doing so, the Application will only offered for downloading to devices that are capable of using NFC features.

More information about that can be found here.



来源:https://stackoverflow.com/questions/10008194/how-to-give-condition-to-android-application-to-run-only-on-nfc-enabled-device

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