这是为了回应question https://stackoverflow.com/questions/5805034/detecting-nfc-on-android-devices
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
我将 API 级别设置为 8,步骤 1 没问题,但是当我编写时hasSystemFeature(PackageManager.FEATURE_NFC)
它说Feature_NFC
不解析为字段,Feature_WIFI FEATURE_BLUETOOTH FEATURE_CAMERA
是那里的选项。
我拜访了Android 开发者网站 http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_NFC,但他们没有提到API级别。
另一个问题是我可以在 AVD 上测试 NFC 应用程序吗?
任何人都可以帮助我这个
谢谢
确保将项目构建目标设置为至少 api 级别 9。
在manifest.xml中包含以下内容
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" /> //If you have icecream sandwich installed.
它将确保您的应用程序也可以在 sdk 8 上运行
还要确保每当您调用 Gingerbread 特定功能时,然后将它们包装到 if 条件中
如下。
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
} else {
if (getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_NFC)) {
//do processing
}
}
为了测试你可以尝试一下打开 NFC Android 模拟器 http://open-nfc.org/wp/editions/android/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)