简体   繁体   中英

NFC NDEF message

i am trying populate my password field on my computer via a android application using NFC. i have a samsung galaxy sIII and a ACR122U USB NFC read/writer. I have read a number of guides but i have not found them very helpful (i am new to this) this is all iv got so far, if anyone could advices a good guide to help or show me how to do this it would be greate help

I have ensured that my AndroidManifest is completed (please note in this I am saying the password i wish to send is Password)

public class NFCHandler extends Activity {
private NfcAdapter mAdapter;
private TextView mText;
private NdefMessage mMessage;

@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create an NDEF message a URL
    mMessage = new NdefMessage(NdefRecord.createMime("text/plain", "Password".getBytes()));

    setContentView(android.R.layout.activity_list_item);
    mText = (TextView) findViewById(R.id.loginPassword);

    if (mAdapter != null) {
        mAdapter.setNdefPushMessage(mMessage, this);
        mText.setText("Password");
    } else {
        mText.setText("This phone is not NFC enabled.");
    }
}
}

If I understand you correctly, you want to send the password in the ndef record. Your code is currently setting the password on the mText field which has no relation to the NdefRecord you created. Instead of using NdefRecord.createUri you should use NdefRecord.createMime("text/plain", "password".getBytes("UTF-8")) if that is what you wish to send to the NFC reader.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM