简体   繁体   English

在Android设备上检查NFC功能

[英]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. 我设置了API等级8,第1步是确定的,但是当我写hasSystemFeature(PackageManager.FEATURE_NFC)它说Feature_NFC亘古不变的决心场, Feature_WIFI FEATURE_BLUETOOTH FEATURE_CAMERA在那里的选项。 I have visited Android developer Site ,but they didn't mention the API level. 我已经访问了Android开发人员网站 ,但他们没有提及API级别。 Another question is Can I test NFC application on AVD? 另一个问题是可以在AVD上测试NFC应用程序吗? Anyone who can help me this Thanks 任何可以帮助我的人,谢谢

Make sure you are setting project build target to at least api level 9. 确保将项目构建目标设置为至少API级别9。

Include folliwng in manifest.xml 在manifest.xml中包含folliwng

<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 这将确保您的应用程序也可以在sdk 8上运行

Also make sure whenever you are calling Gingerbread specific features then wrap them into if condition as follows. 还要确保在调用Gingerbread特定功能时将其包装到if条件中,如下所示。

      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 为了进行测试,您可以尝试打开NFC Android仿真器

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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