Siva
Siva

Reputation: 446

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

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

Upvotes: 1

Views: 872

Answers (4)

NFC guy
NFC guy

Reputation: 10228

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.

Upvotes: 3

Matthew
Matthew

Reputation: 836

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.

Upvotes: 0

adneal
adneal

Reputation: 30794

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

Upvotes: 1

Waynn Lue
Waynn Lue

Reputation: 11375

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

Upvotes: 0

Related Questions