Android 使用NFC写入时的奇怪输出

Android 使用NFC写入时的奇怪输出,android,eclipse,tags,nfc,writer,Android,Eclipse,Tags,Nfc,Writer,现在我有一个NFC项目,我写了一个vcard文件,但输出不是我想要的,这是代码: private NdefMessage getNoteAsNdef() { // byte[] textBytes = mName.getText().toString().getBytes(); // EditText tName = mName; // EditText tNumber = mNumber; String nameVcard = "BEGIN:VCARD"

现在我有一个NFC项目,我写了一个vcard文件,但输出不是我想要的,这是代码:

 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对象上直接使用toString()。你应该改变

(EditText) findViewById(R.id.mName)


对于每个
EditText

如果您使用
(EditText)findViewById(R.id.mName)
并加上
+
字符串,它将获得EditText的方法
toString
。这不是您想要得到的。因此您应该使用
((EditText)findViewById(R.id.mName)).getText().toString()
取而代之。

谢谢你的回答@blackbelt它起作用了!我可以再问一次吗?我在写URL时也有同样的问题,但我确信我使用了这个方法,这是代码私有的NdefMessage getNoteAsNdef(){byte[]textBytes=mLink.getText().toString().getBytes();NdefRecord textRecord=NdefRecord.createUri(“http://“+textBytes”);返回新的NdefMessage(new NdefRecord[]{textRecord});我明白了。下面是您的错误:NdefRecord textRecord=NdefRecord.createUri(“http://“+textBytes”);您正在对byte[]数组调用toString()。您应该将NdefRecord.createUri(“http://“+textBytes”);替换为NdefRecord.createUri(“http://“+mLink.getText().toString());它又成功了!非常感谢@blackbelt!如果你不介意的话,我想再问一件事,但我想这是一个更容易理解为新问题的问题,这里是链接
((EditText) findViewById(R.id.mName)).getText().toString()