-1

I currently trying to make Login System using NFC Card. The idea is, Android will write username to the NFC Card, then when the card is scanned on Android, the user on the card will be logged on automatically.

  1. Is this can be done? (please don't judge whether is logical or not)
  2. If it can be done, is there any in depth tutorial to do it?

The tech on my card is:

  • NfcA
  • Mifare Classic 1K
  • NdefFormatable

I already search for few days for this and can't find any solution that work.

EDIT Thank you all for you answer. The problem is resolved.

If anyone who need some code, you can download it at https://drive.google.com/file/d/1fADWUYxCxFIMqLIyeYrv7Q9HDjd99PgJ/view?usp=sharing

This rar contains java file, xml file, and txt file for a little explanation.

JNTX 1412
  • 65
  • 13
  • There will already be many methods and applications. Specifically, what device, what system do you want to log in to and then use? Adding those things will help you get answers and advice. – kunif Dec 31 '19 at 07:10
  • Thanks for asking. As I've stated on my question, it'll be used on Android device and Android System. The use of the card is for login purpose. Lets say there's an Android App that I make and have login page. By scanning the NFC, the user on the NFC will be automatically logged in. The apps also handling registering new card for user, hence I need the write feature – JNTX 1412 Jan 01 '20 at 01:34

1 Answers1

1

Can this be done? yes

Most tutorials and the Android documents point you to using enableForegroundDispatch but this way of using NFC has a lot of problems, it can produce unreliable reads in real user operations as it pauses your app to do the read. It also very unreliable writes in real user operations as it misdirects users with a beep before the write has completed.

It is better to use enableReaderMode https://developer.android.com/reference/android/nfc/NfcAdapter.html#enableReaderMode(android.app.Activity,%20android.nfc.NfcAdapter.ReaderCallback,%20int,%20android.os.Bundle)

But I've not found a tutorial for this, but some pointers in other answers I've given below.

An Example of enableReaderMode is at https://stackoverflow.com/a/59397667/2373819

While you probably don't want to or need to go to low level data reading shown in this answer (or low level writing) you probably want to use the higher level NDEF data format instead

For a reliable writes don't assume that the card is in range still when you try to write to it and then handle write errors nicely. The best method I found was to store the data to write until you App is notified that a tag has been detected and then immediately write to the card. Logic for this shown in https://stackoverflow.com/a/59423011/2373819

Andrew
  • 8,198
  • 2
  • 15
  • 35
  • Thanks for answering. Do I need to reformat my card? I've try other tutorial just to verified the card is readed, like when I put the card on my phone it'll change a textview value but to no avail. I try to debug but nothing triggered when I put the card on back of my phone. – JNTX 1412 Jan 01 '20 at 01:41
  • If you are using NDEF to store the data then you code should always detect and handle an unformatted NdefFormatable card by formatting it before write. If you are having problems with code, ask a new question that shows your code. – Andrew Jan 01 '20 at 07:30