read tag UID of a classic mifare 1k or NFC

abcroverix

Member
Licensed User
Longtime User
Hello, I'm new in java and android programming.
I need to read the classic mifare 1k or NFC UID
I tried to use the NFC.GeTagtUID from NFC library 1.1 (posted by Sherlock)
I get an array of 4 bytes. First two bytes are the same to the first two byte of the UID (I can read the UID with another device), but the last two bytes are negative numbers and are wrong.

This is the piece of my code:

If NFC.IsNdefIntent(Activity.GetStartingIntent) Then
Dim XID(20) As Byte
XID=NFC.GeTagtUID(Activity.GetStartingIntent)
end if

For example the last two bytes I get are (in decimal): -54,-73,
but the last two bytes in the UID are (in hex): CA, B7.

Someone can explain to me because this happen?
Where I'm wrong?

Many thanks

Fabio
 

Rafal Galewski

Member
Licensed User
Longtime User
No, work with no formated. Using UID only.
I use it in 4.0.4 android. But from 4.1.1 can't work correctly.


About NDEF formatted tags:

How can I use by Your NFC library formatted tag with no standard Site Code A and B.

I would like to security data writed on Tag.
And I change security key A and B.

How I can read data using Your library with security key changed from standard to another.
Where I can set key A and B using to read data from TAG ?
 
Upvote 0

Rafal Galewski

Member
Licensed User
Longtime User
Yes I know.

But UID in android 4.1.1 cant work.

Now I have information from another forum there is a problem android.
Maybe can be repair and new version.


No depend fromYou.

Thank You
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
NFC built in ID

Would be nice if the library would support reading the built in ID, all apps. I know support this.

Shouldn't be very hard to do and because of NFC becoming bigger (100+ plus phones support it) it makes sense.

Cheers,
 
Upvote 0

Rafal Galewski

Member
Licensed User
Longtime User
NFC - how to unblock telephone

Standard NFC create intent only when we have telephone active ( no sleep).

But Can I sleep off when I put NFC TAG on my phone ?

I put a NFC TAG and telephone execute sleep off and start unblock procedure.

Pass PIN for example.

This can be realisase ?

maybe someone has an idea how to implement?
 
Upvote 0

Olex123

New Member
Licensed User
Longtime User
Get UID Problem on Android 4.1.1 and later

Hello all, I got the same problem using the NFC 1.22 library to get the UID from Mifare Cards on Android 4.1.1 and later. On previous Android versions it works fine. Is there a fix available or another known way to solve this problem ? Thank you in advance.
 
Upvote 0

Olex123

New Member
Licensed User
Longtime User
Hello Erel,

Using NFC.IsNdefIntent(Activity.GetStartingIntent) fails but worked on older android Versions.

Using the NFC.IsMifareClassic(Activity.GetStartingIntent) works on both versions and so the problem is solved :)

Thanks for your attention.
 
Last edited:
Upvote 0

StevieDk

Member
Licensed User
Longtime User
Hi,
I have done a project for transportation Mifare tags, used for paying at the public transport, so the user can read the amount left on the card. ( amount of money or trips, depending on the type of card). Now i would like to write on the MIFARE card, so i can be able to load trips, or money to the card after they are payed by credit card; I have allready done that a few years ago, but making the fisical writing of the card, at the bus, the rest all done in virtual.
I would like to know if NFC lib, which is an excellent lib, would be upgraded soon to be able to write sectors on a MIFARE tag.
If not, i would like to collaborate in helping to do it, maybe based on the actual NFC lib :rolleyes:
I am farely new on b4a, not in programming niether with java, c#, and c, but i do not know which can be the process i have to follow so i can collaborate with all you.:(
Thank for your help
Steve
 
Upvote 0

chfajardo

Member
Licensed User
Longtime User
Erel, i have a question:
I am using the NFC library to read Mifare Classic 1K. Everithing goes well if i use the default keys A and B, But if i change the key, it is not working.
For example, i am using the key AAAAAAAAAAAA instead of FFFFFFFFFFFF, but in the sample i have, the key length is 16 bytes and not 6 (used in Mifare Classic).

The sample as i have it:
"
Dim i As Int
Dim key(16) As Byte
Dim mfc As MiFare

For i = 0 To 15
key(i) = 255 '0xFF
Next

If NFC.IsMifareClassic(Activity.GetStartingIntent) Then
'Dim StrData As String
mfc.Initialize(Activity.GetStartingIntent)
If True = mfc.ReadSector(sector,key,1) Then
...................................."

How can i set the key to "AAAAAAAAAAAA" ?

Waiting for your reply,

Carlos H. Fajardo.
 
Upvote 0

chfajardo

Member
Licensed User
Longtime User
Upvote 0

chfajardo

Member
Licensed User
Longtime User
OK, can you tell me how to create a topic? I only know how to post replies in the forum.
Any help with these libraries would be apreciated.

It still doesn't mean that I'm familiar with these libraries. I recommend you to avoid limiting your questions to a single member next time.
 
Upvote 0

Lectos

Member
Licensed User

Hello chfajardo:

I'm interested in to read Mifare UID, not the data. Can you please post an example of your procedure?

Thanks in advance.
 
Upvote 0

chfajardo

Member
Licensed User
Longtime User
Hello chfajardo:

I'm interested in to read Mifare UID, not the data. Can you please post an example of your procedure?

Thanks in advance.

Of course!

Be aware that only a few smartphones are able to read Mifare Cards using NFC, but it is worth a try!

This is the code for reading the NFC UID:

Put this in Process_Globals:

Private nfcIntent As Intent

Sub ConvertToUnsigned(b As Byte) As Int
Return Bit.And(b, 0xFF)
End Sub

Sub read_NFC_UID(nfcIntent1 As Intent) As String
Dim XID(20) As Byte
Dim i As Int
Dim bc As ByteConverter
Dim NFC_UID As String
NFC_UID = ""
If NFC.IsNdefIntent(nfcIntent1) Then
XID=NFC.GeTagtUID(nfcIntent1)
For i = 0 To NFC.GeTagtUID(nfcIntent1).Length-1
XID(i)= ConvertToUnsigned(XID(i))
Next
NFC_UID = bc.HexFromBytes(XID)
End If
Return NFC_UID
End Sub

In the Activity_Resume, put this:

nfcIntent = Activity.GetStartingIntent
NFC_UID = read_NFC_UID(nfcIntent)

I am using these libraries:
byteconverter, core, mul, nfc, nfcforeground and rsnfctagwriter
But i think you can do it with only:
byteconverter, core, nfc, nfcforeground

Also, put this on manifest editor:

AddActivityText(main, <intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" />
</intent-filter>)
AddActivityText(main, <intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>)

I hope it helps you!
 
Upvote 0
Top