Question

so now i have a project of NFC, i write a vcard file but the output is not what i want this is the code:

 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
    });
}

the output is some kind of weird word and always have an "@"

i don't get it, is there something i must add?

Was it helpful?

Solution 2

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";

you are using directly toString() on the EditText object. You should change

(EditText) findViewById(R.id.mName)

with

((EditText) findViewById(R.id.mName)).getText().toString()

for every EditText

OTHER TIPS

If you use (EditText) findViewById(R.id.mName) and plus + a String, it will get the method toString of editText .This is not what you want to get.So you should use ((EditText) findViewById(R.id.mName)).getText().toString() instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top