0
NFC 태그에서 ndef 메시지를 읽고 쓰는 앱을 작성했습니다. 내 앱은 NDEF 메시지로 두 개의 NDEF 레코드를 읽고 쓸 수 있습니다. 그러나 NDEF 메시지 내에 NDEF 레코드가 하나만있는 태그를 표시하면 응용 프로그램이 손상되었습니다. 나는 그 이유를 알고있다. 또한 문제를 해결하는 방법도 알고 있지만 문제를 해결하려면 NDEF 메시지에서 레코드 수를 얻는 방법을 알아야합니다.NDEF 메시지의 총 레코드 수는 어떻게 얻습니까?
NdefMessage[] msgs = getNdefMessagesFromIntent(intent);
NdefRecord ndefRecord1 = msgs[0].getRecords()[0];
NdefRecord ndefRecord2 = msgs[0].getRecords()[1]; //problem is here
byte[] payload1 = ndefRecord1.getPayload();
byte[] payload2 = ndefRecord2.getPayload();
//Get the text encoding
String textEncoding1 = ((payload1[0] & 0200) == 0) ? "UTF-8" : "UTF-16";
String textEncoding2 = ((payload2[0] & 0200) == 0) ? "UTF-8" : "UTF-16";
//Get the Language Code
int languageCodeLength1 = payload1[0] & 0077;
int languageCodeLength2 = payload2[0] & 0077;
String text1 = null;
String text2 = null;
//Get the Text
try
{
text1 = new String(payload1, languageCodeLength1 + 1, payload1.length - languageCodeLength1 - 1, textEncoding1);
}
catch (UnsupportedEncodingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
//Get the Text
try
{
text2 = new String(payload2, languageCodeLength2 + 1, payload2.length - languageCodeLength2 - 1, textEncoding2);
}
catch (UnsupportedEncodingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
String payloadString1 = new String(text1);
String payloadString2 = new String(text2);
record1.setText(payloadString1);
record2.setText(payloadString2);