Java Question Adding new functionalities and tags decoding to NFC library

Rafal Galewski

Member
Licensed User
Longtime User
Good JOB

Thank You for Good Job.

I can Help You in this topic:

"I don't know how to put the "filter_nfc.xml" under "res/xml" directory."

You should go to Yor project folder then Objects\res\xml

And please create nfc_tech_filter.xml

But You have to change files setings to read-only


I would be waiting for posibilites create own key A and B and use it to format Mifare card to all sector.
And also writing data to choose sectores.
 

Rafal Galewski

Member
Licensed User
Longtime User
The attachments are the new version of NFC library and a sample application. I added some extra java code to the library by Sherlok and Erel.

Here's how to use the lib:
1.initialize a "MiFare" object.
2.Call ReadSector() method with 3 parameters: SectorIndex, KeyData, KeyType
3.If succeeded, retrieve the data block by block with method GetBlockData()

B4X:
Sub Read()
   Dim key(16) As Byte 
   Dim block_data() As Byte
   Dim bc As ByteConverter



   
   Dim i As Int
   For i  = 0 To 15
      key(i) = 255 '0xff
   Next

   'btnClear
   Dim mfc As MiFare
   Log("Check if the card is MF classic")
    If NFC.IsMifareClassic(Activity.GetStartingIntent) Then
      Dim StrData As String
      mfc.Initialize(Activity.GetStartingIntent)
      If True = mfc.ReadSector(0,key,0) Then' Read sector 0, key, type 0(as keyA)      
         Log("Read sector done")
         For i = 0 To 2 'read 3 blocks of data
            block_data = mfc.GetBlockData(i)
            StrData =  bc.HexFromBytes(block_data)
            Log( "data:" & StrData)
            If i = 0 Then
               Label1.Text = StrData
            Else If i = 1 Then
               Label2.Text = StrData
            Else If i = 2 Then
               Label3.Text = StrData
            End If
         Next
      End If
   End If
End Sub

In manifest editor, I added "android.nfc.action.NDEF_DISCOVERED" and "android.nfc.action.TAG_DISCOVERED" intent filter. Actually "android.nfc.action.TECH_DISCOVERED" is better than NDEF_DISCOVERED but it needs some code like:
B4X:
  <meta-data android:name="android.nfc.action.TECH_DISCOVERED"
          android:resource="@xml/filter_nfc" />

I don't know how to put the "filter_nfc.xml" under "res/xml" directory. Maybe Erel knows.

Good luck




When I try open sample project I have error missing 2 files:
-Main.bal
-UriView.bal

If You could please shere it.

Thank You :sign0098:
 

Rafal Galewski

Member
Licensed User
Longtime User
If You could in future please add to this library method Save data in sector with key.
Becouse nowe we can only read data from sector.
But we can't save data in sectores.

Thank You
 

jjcc

Member
Licensed User
Longtime User
When I try open sample project I have error missing 2 files:
-Main.bal
-UriView.bal

If You could please shere it.

Thank You :sign0098:

Sorry for the error and delay. It was in rush because I was busy on other project.

I've updated the code. Meanwhile, fixed a couple of bugs in Lib.
 

Attachments

  • NFC2.22.zip
    8.9 KB · Views: 1,469
  • MifarelReader.zip
    3.5 KB · Views: 1,203

Rafal Galewski

Member
Licensed User
Longtime User
NFC and sleep 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?
 

walterf25

Expert
Licensed User
Longtime User
NFC Help

Hello, i've tried this library and it seems like there's something missing, I copied both files .xml and .jar to my additional libraries folder, but when I open the example and try to run it i get an error, it seems as there's still missing a file.

the problem is at this line

B4X:
Dim mfc As MiFare

that line remains in color red, which means that there's no library associated with MiFare, what am I missing?

thanks,
Walter
 

jjcc

Member
Licensed User
Longtime User
Hello, i've tried this library and it seems like there's something missing, I copied both files .xml and .jar to my additional libraries folder, but when I open the example and try to run it i get an error, it seems as there's still missing a file.

the problem is at this line

B4X:
Dim mfc As MiFare

that line remains in color red, which means that there's no library associated with MiFare, what am I missing?

thanks,
Walter

I think you have both versions and B4A was confused. B4A might search lib files in its standard location first.

To fix this, you can verify the NFC version in the "Libs" tab at the right side of IDE. If it's 1.00, then move the NFC.xml and NFC.jar in the standard lib location (i.e. "your location\Basic4Android\Libraries\").

Good luck!
 

StevieDk

Member
Licensed User
Longtime User
Hello,
NFC lib works wonderfull, thanks all for your work. I will need to write on a MIFARE tag, as far as i know, that feature is not implemented yet.
I will like to help on it, so we can all have the utility. I am farely new on this blog, so i am not use on where / how to access java code of the lib so i can continue ( or try to) your excellent work.
Thanks

Steve
 

jjcc

Member
Licensed User
Longtime User
Hello,
NFC lib works wonderfull, thanks all for your work. I will need to write on a MIFARE tag, as far as i know, that feature is not implemented yet.
I will like to help on it, so we can all have the utility. I am farely new on this blog, so i am not use on where / how to access java code of the lib so i can continue ( or try to) your excellent work.
Thanks

Steve
Thanks Steve.

I have no problem to share the source code. If Erel agrees I can put the code into the Github. Most of the code belongs to Erel I think.
 

jjcc

Member
Licensed User
Longtime User
I'll upload the source code later after I clean up some mess.

For now I have a new version with limited NfcV functions. A demo is attached to show how to use the NfcV functions. Only read no write for now.

I've tested a ISO 15693 tag(ICODE SLI/NXP SL2 ICS2001). It works fine.
 

Attachments

  • NFC1.23.zip
    29.2 KB · Views: 757
  • NfcVReader.zip
    3.8 KB · Views: 759

Chelu

Member
Licensed User
Longtime User
I have read many post about NFC.
Before wasting more time I would like to know if this library can do the following:
I want my phone it acts backup my RFID card.
I mean, no need to write, but I need a NFC reader detects my phone as my card
If this were possible, I wonder too if a trigger event or intent to make reading on my phone that could capture.

Thank you very much.
 

jjcc

Member
Licensed User
Longtime User
Chelu,
The function you want is card simulation as opposed to reader which is a quite new function. I believe Android 4.4 supports the function.

The current lib can not meet your requirement.
 
Top