简体   繁体   中英

Checking NFC feature on Android Device

This is in response to question

Step #1: Put this in your manifest:

<uses-feature android:name="android.hardware.nfc" android:required="false" />
Step #2: Call hasSystemFeature(PackageManager.FEATURE_NFC) on PackageManager to see if NFC is available on the current device

i set the API level to 8,Step 1 is ok, but when I write hasSystemFeature(PackageManager.FEATURE_NFC) it says Feature_NFC doesnot resolve to a field, Feature_WIFI FEATURE_BLUETOOTH FEATURE_CAMERA are the options there. I have visited Android developer Site ,but they didn't mention the API level. Another question is Can I test NFC application on AVD? Anyone who can help me this Thanks

Make sure you are setting project build target to at least api level 9.

Include folliwng in manifest.xml

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" /> //If you have icecream sandwich installed.

It will ensure that your application will be runnable on sdk 8 also

Also make sure whenever you are calling Gingerbread specific features then wrap them into if condition as follows.

      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {

    } else {
        if (getPackageManager()
                .hasSystemFeature(PackageManager.FEATURE_NFC)) {
            //do processing
        }
    }

For testing You can give a try to Open NFC Android emulator

FEATURE_NFC是从API级别9定义的,但是您仍然可以使用常量值“ android.hardware.nfc”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM