Android Question Use pin, patron, fingerprint to unloock my app. Fail

jvrh_1

Active Member
Licensed User
I am trying to use the complete code that Erels wrote at this post: #13

B4X:
Sub Activity_Click
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   Dim KeyguardManager As JavaObject = ctxt.RunMethod("getSystemService", Array("keyguard"))
   Dim in As Intent = KeyguardManager.RunMethod("createConfirmDeviceCredentialIntent", Array("Title", "Description"))
   If in.IsInitialized = False Then
       Log("No password set!")
       Return
   End If
   StartActivityForResult(in)
End Sub

Sub StartActivityForResult(i As Intent)
   Dim jo As JavaObject = GetBA
   ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null) 'ion is a process global object: Private ion As Object
   jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub

Sub GetBA As Object
   Dim jo As JavaObject
   Dim cls As String = Me
   cls = cls.SubString("class ".Length)
   jo.InitializeStatic(cls)
   Return jo.GetField("processBA")
End Sub

Sub ion_Event (MethodName As String, Args() As Object) As Object
   If Args(0) = -1 Then 'resultCode = RESULT_OK
       Log("User unlocked successfully!")
   End If
   Return Null
End Sub

But when I complie it firstly appears "Main - 62: Variable 'ion' no declarada (warning #8)" although I can execute the code.
After that, when I use a debug mode and I use F8 step by step slowly, it works, but If I use realase mode or debug mode with out pressing F8 key, It does not work , the appe colses and appears:
** Activity (main) Pause event (activity is not paused). **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Unexpected event (missing RaiseSynchronousEvents): ion_event
Check the unfiltered logs for the full stack trace.
Error occurred on line: 75 (Main)
java.lang.NullPointerException: Attempt to read from null array
at b4a.example.main._ion_event(main.java:616)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at anywheresoftware.b4a.shell.Shell$2.run(Shell.java:321)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7399)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
** Activity (main) Pause event (activity is not paused). **

I do not how to resolve it.
 

sirjo66

Well-Known Member
Licensed User
Longtime User

As you see in the code, you need to declare "ion" variable as "Private ion As Object" in the section "process global"
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…