有一個NFC工程,寫了一個電子名片文件,但是輸出不對:
private NdefMessage getNoteAsNdef() {
// byte[] textBytes = mName.getText().toString().getBytes();
// EditText tName = mName;
// EditText tNumber = mNumber;
String nameVcard = "BEGIN:VCARD" +"\n"+ "VERSION:2.1" +"\n" + "N:;" + (EditText) findViewById(R.id.mName) + "\n" +"ORG:"+"\n"+ "TEL;WORK:" +(EditText) findViewById(R.id.mNumber)+ "\n" + "END:VCARD";
byte[] uriField = nameVcard.getBytes(Charset.forName("US-ASCII"));
byte[] textBytes = new byte[uriField.length + 1];;
System.arraycopy(uriField, 0, textBytes, 1, uriField.length);
NdefRecord textRecord = new NdefRecord(
NdefRecord.TNF_MIME_MEDIA, "text/x-vcard".getBytes(), new byte[0], textBytes);
return new NdefMessage(new NdefRecord[] {
textRecord
});
}
輸出的文字都不正確,還有@字符。
String nameVcard = "BEGIN:VCARD" +"\n"+ "VERSION:2.1" +"\n" + "N:;" + (EditText) findViewById(R.id.mName) + "\n" +"ORG:"+"\n"+ "TEL;WORK:" +(EditText) findViewById(R.id.mNumber)+ "\n" + "END:VCARD";
這裡面就有問題
應該是這樣吧:
((EditText) findViewById(R.id.mName)).getText().toString()