Reputation: 2045
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
Upvotes: 2
Views: 4438
Reputation: 28093
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
Upvotes: 6
Reputation: 4157
FEATURE_NFC is defined from API Level 9, but you can still use the constant value "android.hardware.nfc".
Upvotes: 0