Hallo Erel, you are right. I will try to summarize and explain better my app and my problem.
My MAIN has TWO BUTTONS, Button1 and Button2.
As soon as a NFC TAG is detected, the Button1 background becomes RED and if I push it, a MsgBox shows me the TEXT in the TAG memory.
This app works correctly.
Here's the code:
Code:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim NFC As NFC
Dim UID_NFC As String
Dim Stringa_NFC As String
Private Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
NFC.EnableForegroundDispatch
If NFC.IsNdefIntent(Activity.GetStartingIntent) Then
Dim records As List
Button1.Color = Colors.Red
records = NFC.GetNdefRecords(Activity.GetStartingIntent)
For i = 0 To records.Size - 1
Dim r As NdefRecord
r = records.Get(i)
Log(r.GetAsTextType)
Next
Stringa_NFC=r.GetAsTextType
End If
End Sub
Sub Button1_Click
Button1.Color=Colors.Gray
Msgbox(Stringa_NFC, "TEXT IN THE TAG")
End Sub
Sub Button2_Click
Msgbox(UID_NFC, "TAG UID")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Now pushing Button2 I would like to show with a MsgBox the UID of the TAG.
I put the JavaObject "TagTech" as you described in your post #64451, but it does not work.
Here's the code:
Code:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim NFC As NFC
Dim UID_NFC As String
Dim Stringa_NFC As String
Private Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
Dim jo As JavaObject = TagTech
Dim Tag As JavaObject = jo.RunMethod("getTag", Null)
Dim rawId() As Byte = Tag.RunMethod("getId", Null)
'Log(bc.HexFromBytes(rawId)) 'bc = ByteConverter
NFC.EnableForegroundDispatch
If NFC.IsNdefIntent(Activity.GetStartingIntent) Then
Dim records As List
Button1.Color = Colors.Red
records = NFC.GetNdefRecords(Activity.GetStartingIntent)
For i = 0 To records.Size - 1
Dim r As NdefRecord
r = records.Get(i)
Log(r.GetAsTextType)
Next
Stringa_NFC=r.GetAsTextType
End If
End Sub
Sub Button1_Click
Button1.Color=Colors.Gray
Msgbox(Stringa_NFC, "TEXT IN THE TAG")
End Sub
Sub Button2_Click
Msgbox(UID_NFC, "TAG UID")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
With this code I receive the ERROR:
"Error parsing program.
Error description: Undeclared variable 'tagtech' is used before it was assigned any value.
Occurred on line: 35 (Main)
Dim jo As JavaObject = TagTech"
I tried to declare in the Sub Globals the TagTech variable with this code:
Code:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim NFC As NFC
Dim UID_NFC As String
Dim Stringa_NFC As String
Private Button1 As Button
Dim TagTech As TagTechnology
End Sub
But then the problem is the LOG posted at the beginning of the thread:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 36 (Main)
java.lang.RuntimeException: Object should first be initialized (TagTechnology).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at b4a.example.main._activity_resume(main.java:411)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at b4a.example.main.afterFirstLayout(main.java:108)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
** Activity (main) Pause, UserClosed = false **
I hope that now the issue is a little more clear and sorry for this verbose reply.
Thank you very much again for your help and for your patience...
Ciao
Fabio