出于某种原因,即使我启用了NFC,getSystemage()。hasSystemFeature(NFC_SERVICE)也会在SamSung S5中返回null,如下面的屏幕截图所示。
以下是我用来测试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;
}
我有什么不该做的不同吗?