Widget failing to invoke desired code

PFlores81

Active Member
Licensed User
Longtime User
I am mobile right now so I cannot provide a portion of my code, my widget service is up and running. Upon clicking the widget it is supposed to invoke the screen lock..

Mind you this is still alpha build as there is lots to be added. I'm pretty sure the screen lock code is correct.
If not, I could use some constructive criticism.

B4X:
MAIN
Sub LockScreen
    
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "keyguard", "java.lang.String")
    r.Target = r.RunMethod2("newKeyguardLock", "keyguard", "java.lang.String")
    r.RunMethod("reenableKeyguard")
End Sub

Sub OnOff_CheckedChange(Checked As Boolean)
   If OnOff.Checked=True Then
   
   ToastMessageShow("Service Started",True)
   End If
   If OnOff.Checked=False Then
   ToastMessageShow("Service Terminated",True)
   Service_Destroy
   End If
   
End Sub

Sub Service_Destroy

End Sub
Sub ImageView1_Click
   LockScreen
   ToastMessageShow("Device Locked",True)
End Sub

B4X:
Widget

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
Dim rv As RemoteViews
End Sub
Sub Service_Create
rv = ConfigureHomeWidget("Lock", "rv",0, "SecureLock")
End Sub

Sub Service_Start (StartingIntent As Intent)
If rv.HandleWidgetEvents(StartingIntent) Then Return
End Sub
Sub rv_RequestUpdate
   rv.UpdateWidget
End Sub
Sub rv_Disabled
   StopService("")
End Sub
 
Last edited:

PFlores81

Active Member
Licensed User
Longtime User
Haha, yeah sorry ill be posting it as soon as I get home.

What its supposed to do is invoke the lock screen via image view click. However, its not doing that at all. It just sits. Ill post all relevant code in about 5 minutes when I get home.
 
Upvote 0

PFlores81

Active Member
Licensed User
Longtime User
It is not very clear to me. Maybe it is better to post the Project as a ZIP file. In the IDE, select File->Export as Zip.

It seems to me that the Imageview1_Click sub should be in the service module not the activity.

I updated the first post with the source. It's far from complet, but getting the widget to invoke the lock screen is important.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Okay, after making many changes I got the ImageView1_Click working.
However your Lockscreen code isnt doing anything.

I put the ImageView on the panel in the Designer.
Put the LockScreen sub in the service. It cannot be called from the Activity since it is paused.
I made many other minor adjustments, you can see the difference.
 

Attachments

  • SecureLock2.zip
    14.7 KB · Views: 181
Upvote 0

PFlores81

Active Member
Licensed User
Longtime User
I appreciate your help. Ill have to look further into the lock code. I need to get the lock working before I can add anything else to it.
 
Upvote 0

PFlores81

Active Member
Licensed User
Longtime User
Upon further investigation, the app needs to be enabled under device administrators. Can b4a do this yet?
 
Upvote 0
Top