Trying to create a simple, beginner level NFC read/write app just to figure out the basics.
Started with App inventor pre-made BallShuffle app (NFC game) but it doesn't work well. Receiving a message the tag is empty (attached please see App_msg1 phone screenshot). The app is downloaded as the "apk" file (not working in the dev/test environment.
Created simple test app (write/read button) and it does read and write but during the read session it throws a Runtime error (image App_msg2) attached) saying that "API can not be called while activity is paused" ?
I do not use any API in my super simple read/write test application
It reads/writes to NTAG213 but can't do it with NTAG216
Available documentation on the App Inventor 2 site is not sufficient for me to figure out what I am doing wrong.
Any help in form of an working app, direction to a good paper about the NFC for AppInventor or any other suggestion is more than welcome.
I use Android Samsung S3 with 5Gb of free memory space.
Reinstalled App inventor on it, cleared cash, reset all connections, reload the apps etc.. - no luck
Thank you in advance for your feedback
--
Is the Ball Shuffle app the same as the Cup Game?
--
Post a downloaded blocks image for more ideas.
It reads/writes to NTAG213 but can't do it with NTAG216
Factor out AI2 and try a different NFC app -
See this thread ...
Yes, the Ball Shuffle app is the same app as the Cup Game [NFC Cup Game for AI2 ]
I am in process of posting the "aia" of my test app, screens of the blocks involved and also the designer's view of the same.
Started to think that I might need:
A) some time delay between switching from the "read" to "write"
B) some mechanism to "control" interruptions that could occur while my app is working with the NFC
P.S. learning this interface, trying to attach the rest...
OK, good idea.
--
Will test different NFC apps and different tags to see if it happens with any other combination.
Than will post here and turn back to my test app
Is your new tag type text-only?
Note the disclaimer at http://ai2.appinventor.mit.edu/reference/components/sensors.html#NearField
--
Not sure about the tag type, Downloading some NFC "tools" to see "deeper" into the tags' structure. I thought it is just a memory space (generally an address space of a defined size) and it would depend only on what one writes into it. From the data structure entered - yes, I am entering only text. Will post back after I "scan" the tags for their structure
--
Downloaded an "api" file from this forum from an user who reported similar issues in 2013 (the original post is closed but I attached the app - called NFCtest3). His appwill try to write but will throw the "empty tag" message in that process and also a nasty Run-Time error (android phone screen shot attached in jpg). Tag specs (of the tag used in this scenario) are below (acquired with an NFC scan tool). The further I go with testing the more errors are coming up.
Working on finding a stable application that can consistently write / read - just to weed out possible bad tags and start with MIT App Inventor NFC feature testing.
Tag Specs attached this time.
Note: the android phone screen shot is from my phone (today) after I run other forum member's app (downloaded from a 2013 post)
TAG USED - SPECS:
Manufacturer: NXP Semiconductors
IC Type = NTAG213
NFC Forum NDEF-compliant tag = Type 2 Tag
Capacitance = 50pF
Protocol = ISO/IEC 14443-3
Encoding = UTF-8
--
Maybe some manufacturer NFC reader apps from the Play Store might help
with the finger pointing.
What do they say about your reader and tags?
--
no, that was the original App (from 2013) I downloaded to compare. Left it as it was just to run it few times. Will fix the error tonight.
In the meantime I tried 4 free apps (downloaded from the Google Play store) and only 1 can read and write consistently to the 3 tags I am using as a test group (two NTAG216 and one NTAG213). So, that would mean I can exclude the smart device I am using (was thinking I need to update the "OS") and the tags as a root cause for my problems (?)
Basically, back to the AI2 and figuring out what is triggering the problems
Knowing that delays (timers/counters) might not work well in the AI2 I still have a feeling that timing of the "code" and syncing it with phone/tag proximity (bring tags in for read/write + move a phone away when done) are playing a role here.
Difficult to troubleshoot (trying to figure out appropriate test code I could run step by step)..
--
OK, 3rd day.
Searching for the root cause I created a super simple 2 blocsk app. (images attached). One button to enable "read" and color changing block to signal a tag has been read. Created "apk" file and installed it on my cell phone (Android samsung S3)
In addition, I am using one stable NFC write/read app downloaded off of the Google Store which is not showing any issues
Also I decided not to swing and move the phone around but rather;
- place it over (on) the tag
- keep it there, static for a while
- only _then_ interact with my app UI (click the "read" button) to enable the read thread. Here is what I observed;
1) placed a phone over the tag
2) waited 1/2 -1 sec (before I would touch the 'read' button)
3) before I had a change to touch the UI (the "read" button), the phone interacted with the tag and popped up the message "Empty Tag" ... "unknown tag type"...(attached: Image 1)
4) repeated the above several times and got the same results
At this point I wanted to understand if this is some issue due to the apps I created or tags or the cell phone ? So I continued:
5) shut off my NFC app (that I created), left the cell phone NFC = "ON" and put it over a tag (repeated for several tags)
6) received the same "Empty Tag" ".. "Unknown tag type" message for the NTAG216 which had its memory wiped with some "Tag Tool"
7) received a different popup message for NTAG213 and NTAG216 that had some txt on them - asking me whihc app I want to use to interact with them (see Image 2 attached)
Now it seemed clear the issue of the "Empty Tag" messasge was not caused by my apps but rather by the cell phone NFC feature - or better to say by some system level process related to the NFC being set "ON" (in the PC world I would say - "NFC driver issue" to express what I think is messign up with me here). To conclude I did the following:
8) power cycled the phone, set NFC= OFF, placed the phone on a tag -- > no reaction, nothing
9) set the NFC= ON, placed the phone on a tag -- > got the same messages and behavior described under 6 and 7 above....
Conclusion:
A) Some "default" app / feature (unknown to me), related to my phone's NFC settings (when NFC=ON) coexists with the NFC apps I created and installed and is interacting with the tag, regardles of my installed app (see 5, 6, 7 above). This could help explain intermittent success /error episodes observed previously during read / write sessions.
A) Some "default" app / feature (unknown to me), related to my phone's NFC settings (when NFC=ON) coexists with the NFC apps I created and installed and is interacting with the tag, regardles of my installed app (see 5, 6, 7 above). This could help explain intermittent success /error episodes observed previously during read / write sessions.
B) The tags are not the issue (NTAG213, NTAG 216) but the interaction between that NFC generic/built in "process" and my own apps
Now, ideas are needed to find out what that "hidden" process is and how to neutralize it ?
Given the structure of the message presented on the image 2 -
--
Two ideas ...
The NFC TagRead event has a message local variable that ostensibly should contain the
newly arrived message. You don't show it. (Too obvious)
Does your phone have a section in its Settings app for control of NFC operations?
That might prove informative.
--
A search for NFC using this board's search box found this idea ...
The tags only work after they have been initialized by the app mentioned in that post .
--
Saw those posts earlier but only now I think I can interpret them. The phone seems to be behaving as designed (?).
1. The app mentioned in the link you provided is called "Tags" and that is the one which seems to be jumping out every time the NFC is set to ON and a tag is brought close to the phone, regardless of what my own NFC apps are doing.
2. When I bring a pre-formatted tag to the phone, it asks me which of the NFC apps I want to use (sounds OK)
3. When a tag is unformatted or its memory is wiped out - the "Tags" app (in the phone Application Manager menu "ALL") throws the "unknown tag type" messasge
It seems I need to test the following scenarios to conclude this case';
A) Disable that "bult in" app called "Tags" (your link) and record what will change due to that
B) If that helps reduce popups etc - I need to see if I can shut off that app ("Tags") from within my AI2 app to make sure that my app works fine on other phones
C) Figure out a way to create time delays or loops betwen the NFC "actions" - why ? - because it seems the NFC is firing continuously as long as it is set to "ON" on the phone (perhaps it is that app "Tags" making it do so) and also when (within the AI2 app) the "read mode" is set to "true".
It is not clear to me if the NFC "write" event stops automatically wiht the "TagWritten" event or if it continues firing. Also, will the app stop reading after the TagRead event "happens" or does it continue reading untill we set TagRead to False ?
Would you know of any additional literature about the AI2 NFC ?
What is available on the AI2 web site is pretty minimalistic - at least for me.
Thank you for your help so far !
So I turned off that application (Settings - Application Manager / "tab ALL / Tags app--> see attached images) but it didn;t help.
If the NFC =ON and I bring a tag close to the phone it now either makes a sound (in case of an unformatted tag) or opens a window asling me to select which NFC app I want to use (in case of a configured tag).
I downloaded a 3rd party NFC tag which used to be very stable and has only 2 buttons: Read from and Write to the tag. I start the app and am not touching neither button. If I bring a configured tag to the phone, the app suddently reads it without me asking it to do that.
Trying to find how to stop this unwanted behavior because it affects even 3rd party, stable apps by taking the control over the NFC feature.
Looking into apps that are Running (screnshot attached) and the only one that seems suspicious to me is the SmartCardService. I don;t see any NFC related app/name ?
--
Also, I am trying to understand what is the "WriteType" property and how to use it ?
--
C) Figure out a way to create time delays or loops betwen the NFC "actions"
- why ? - because it seems the NFC is firing continuously as long as it is
set to "ON" on the phone (perhaps it is that app "Tags" making it do
so) and also when (within the AI2 app) the "read mode" is set to "true".
AI2 is event driven, unlike Arduinos .
You should never loop, only respond to events firing.
The only exception is when you are looping thru a data structure.
Otherwise you will freeze the app.
The documentation is indeed sparse...
NearField
Non-visible component to provide NFC capabilities. For now this component supports the reading and writing of text tags only (if supported by the device)In order to read and write text tags, the component must have itsReadMode
property set to True or False respectively.Note: This component will only work on Screen1 of any App Inventor app.Properties
LastMessage
ReadMode
TextToWrite
WriteType
Events
TagRead(text message)
- Indicates that a new tag has been detected. Currently this is only a plain text tag, as specified in the manifest. See Compiler.java.
TagWritten()
- Event for TagWritten
Methods
none
Google is your friend.
Some surprising results, at least surprising for me
Set my phone NFC to ON.
Created super simple app to read a tag (images attached).
As you can see- I did not even address the "NearField Read Mode" parameter (not in the app)
Even though the literature says the Read Mode should be set to True/False in order to read/write respectively, my app reads tags just fine. NTAG213 and NTAG216 alike. So, it seems the NFC circuit is firing all the time (set by the phone NFC=ON) and the When Near Field TagRead event works/reads regardless of the Read Mode parameter not being set to True..
Next test = create a simple write app, without any reference to the "NearField Read Mode" parameter to see if I will be able to write to a tag in that environment. It will be strange if that shows to be possible
Forgot to ask - can we activate / disactivate phone's NFC setting from within AI2 app?
Reading about the Activity Starter but can't tell if it can interact with the OS / Phone Settings ?
--
Forgot to ask - can we activate / disactivate phone's NFC setting from within AI2 app ?Reading about the Activity Starter but can't tell if it can interact with the OS / Phone Settings ?
Here's a pretty full catalog
Maybe it will answer your question.
This app is for all developers who are developing a app using App Inventor and want to learn more about the activity starter component. App Inventor ActivityStarter lets you play with intent activities and has more than 150 example demo activities.
This app is actually a kind of Activity Starter component. You can make your own activity with all the fields you have in the Activity Starter component in App Inventor and execute the activity. If you want to learn more about the activity starter component in app inventor or are you looking for example activities, then this app is for you!
In this app you will find example intent activities such as:
-Action and classes to all android settings.
-open, edit and view content such as image, audio, video or a file.
-Search for content on web or phone.
-Call, Dial, Email, SMS, MMS. Pick, Call or edit contact
-Geo-location activities for Google Maps, Street view or other route app.
-Photo and video activities
-Google play and install and uninstall apps activities
-Save text to sdcart, copy text to clipboard. Share text with Whatsapp, Hangouts, Drive, Dropbox, Mega.
-External App inventor tools activity demos for AsUtil, Phone Picker for App Inventor, vkTools
* More about App Inventor maintained by the Massachusetts Institute of Technology (MIT).
http://appinventor.mit.edu/
* Note that this app has a lot of permissions because it has to be able to do any activity that you can make in app inventor.
* You can also download the source code of this app, see http://code.google.com/p/appinvactivitystarter
--