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

一个人想着一个人 提交于 2019-12-08 06:36:24

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.

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();
        }

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

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.

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