Android Question NFC Reading

dibesw

Active Member
Licensed User
Longtime User
I have tested this tread:
https://www.b4x.com/android/forum/threads/nfc-reading-and-writing.64451/
that works well
immagine_2022-01-27_184912.png


but when I exit the app and bring the tag close to the smartphone I see this:
can anyone tell me why?
how do i show HELLO WORD?

1643305515334.jpg
 

drgottjr

Expert
Licensed User
Longtime User
look in the designer. the 2 string are there (for your convenience). just clear them
 
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
Please drgottjr, what do you mean?
Apps works well and the 2 string are display well
but when I close the app and I bring the tag under the phone
I see this 2 records with written text/plain
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
ah! now i follow (i think). your device is reading the tag without your app. android can read familiar tags by itself. you need to override that with your app. you have to set the manifest so that android sees your app as an nfc tag reader. then you get the first look at the tag. if you have several apps on your phone that can read nfc tags, you will see a list of apps to choose. if you have no apps set to read the tags, android uses its own default app. did you add anything to your manifest? if yes, did you do it correctly?

if your app is already running, then you are able to look at the tag. if the app is closed, you have to change the manifest if you want to read tags. i will come back with the settings. i have to go now. maybe someone else shows you first. it's simple to do.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
ok, so here:

Manifest changes for NFC:
'End of default text.
AddPermission(android.permission.NFC)
AddActivityText(main,<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http" />
    <data android:scheme="https" />
</intent-filter>
<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="geo" />
</intent-filter>)

add this to your manifest and see what happens. (you can always remove it without problem). what should happen:

1) your app should automatically open and try to read the tag.
2) android asks you which app you want to use to read the tag. (you will select yours ;))
3) the tag is not recognized. therefore: not read
4) there is nothing on the tag.

the manifest changes should allow your app to read plain text, http(s):// urls and tags with gps coordinates (lat/lng). there are others, but i did not add them.

the picture you uploaded that says "nuovo tag raccolto" but has no text means the tag was not read by android's default tag reader. i don't know what the tag is supposed to say. if you try to read with your app (and with manifest changes), maybe you have success. of course, it's always possible there is nothing on the tag or the tag type is different from what the manifest says you can read.
 

Attachments

  • hello.png
    hello.png
    13.7 KB · Views: 137
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
My goal is to read a tag without any NCF apps.
I tested this
B4X:
        WriteNdef(Array( _
                    nfc.CreateMimeRecord("text/plain", "TEXT TEXT TEXT".GetBytes("UTF8")), _
                      nfc.CreateUriRecord("https://www.google.com"), _
                    nfc.CreateUriRecord("tel:+3933311122233")))
and the result is
Screenshot_2022-01-28-09-33-27-851_com.android.apps.tag.jpg

If try like this
B4X:
        WriteNdef(Array( _
                    nfc.CreateUriRecord("TEXT TEXT TEXT"), _
                      nfc.CreateUriRecord("https://www.google.com"), _
                    nfc.CreateUriRecord("tel:+3933311122233")))
the result could be fine but it wouldn't be regular to use CreateUriRecord
Screenshot_2022-01-28-09-35-55-454_com.android.apps.tag.jpg

but I wanted to look for something to make it work with CreateMimeRecord.
I also tried this app (tt_nfcwriter.zip) that i downloaded from community but
allows you to write only one record at a time; I need to write more records
 

Attachments

  • tt_nfcwriter.zip
    20.4 KB · Views: 141
Upvote 0

drgottjr

Expert
Licensed User
Longtime User

Android Question NFC Reading​

the thread is about nfc reading. now you are talking about something else. i am sorry; i do not follow.
 
Upvote 0
Top