您好我正在讀取來自NFC標籤的數據,並嘗試將其與一個字符串進行比較,但if循環比較字符串時失敗。我讀取NFC數據並將其與字符串進行比較的代碼是如。謝謝。比較從NFC標籤讀取數據
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);
}
http://code.google.com/p/ndef-tools-for-android/ – ThomasRS