getPackageManager()。hasSystemFeature(NFC_SERVICE)在Samsung S5中不起作用

时间:2015-08-20 18:37:20

标签: android nfc samsung-mobile android-beam

出于某种原因,即使我启用了NFC,getSystemage()。hasSystemFeature(NFC_SERVICE)也会在SamSung S5中返回null,如下面的屏幕截图所示。

enter image description here

以下是我用来测试NFC服务是否可用并且第一次测试失败的代码

//check for the existence of
    // NFC adapter and beaming capability

    if (!getPackageManager().hasSystemFeature(NFC_SERVICE)){
        //this device is not equipped with NFC
        makeToast("This device does not have NFC hardware.");
        return;
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        // Android Beam feature is not supported.
        makeToast("Android Beam is not supported in this device");
        return;

    }

    // Check whether NFC is enabled on device
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    if (!mNfcAdapter.isEnabled()){
        makeToast("Please enable NFC");
    }

    if(!mNfcAdapter.isNdefPushEnabled()) {
        // Android Beam is disabled, show the settings UI
        // to enable Android Beam
        makeToast("Please enable Android Beam.");
        startActivity(new Intent(Settings.ACTION_NFCSHARING_SETTINGS));
        return;
    }

我有什么不该做的不同吗?

1 个答案:

答案 0 :(得分:1)

NFC_SERVICE不是传递给hasSystemFeature()的有效值。 Use FEATURE_NFC