嗨,我正在从 NFC 标签读取数据并尝试将其与字符串进行比较,但在比较字符串时 if 循环失败。我用于读取 NFC 数据并将其与字符串进行比较的代码为 as。谢谢你。
Parcelable[] messages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
//NdefMessage message = ndef.getNdefMessage();
if (messages != null) {
NdefMessage[] ndefMessages = new NdefMessage[messages.length];
for (int i = 0; i < messages.length; i++) {
ndefMessages[i] = (NdefMessage) messages[i];
}
NdefRecord record = ndefMessages[0].getRecords()[0];
byte[] payload = record.getPayload();
String text = new String(payload);
txtRead.setText(text);
if(text.equalsIgnoreCase("silent")){
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG).show();
AudioManager audiomanage = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audiomanage.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}