Android Question java.lang.NoSuchMethodException: isKeyguardLocked with Sony Xperia

aeropic

Active Member
Licensed User
Longtime User
Hi All,

I've published my little application Camera Unlock on the playstore and I get a crash on a Sony Xperia device. From what I understand, it seems that "iskeyguardLocked" is the root cause

the piece of code in which the keyguard status is checked is this one :
B4X:
Sub CheckLock As Boolean ' permet de tester l'etat locked ou non du téléphone
    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "keyguard", "java.lang.String")
    Return  r.RunMethod("isKeyguardLocked")
End Sub

Is there another way to check if the device is locked or not ?

Any help welcome ...
Thanks
Alain


the crash log :

java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.SCREEN_OFF flg=0x40000000 } in anywheresoftware.b4a.phone.PhoneEvents$16@40582880
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:722)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:138)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: isKeyguardLocked
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
at anywheresoftware.b4a.phone.PhoneEvents$ActionHandler.send(PhoneEvents.java:326)
at anywheresoftware.b4a.phone.PhoneEvents$6.handle(PhoneEvents.java:140)
at anywheresoftware.b4a.phone.PhoneEvents$16.onReceive(PhoneEvents.java:268)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709)
... 9 more
Caused by: java.lang.NoSuchMethodException: isKeyguardLocked
at java.lang.ClassCache.findMethodByName(ClassCache.java:247)
at java.lang.Class.getDeclaredMethod(Class.java:731)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:214)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod(Reflection.java:802)
at com.aeropic.CameraUnlockFree.unlock._vvvvvvvvvv7(unlock.java:104)
at com.aeropic.CameraUnlockFree.unlock._pe_screenoff(unlock.java:111)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
... 14 more
 

aeropic

Active Member
Licensed User
Longtime User
Thanks Erel,

I missed this API compatibility business ...
This raises 2 additional questions :

1- how to tell the playstore that my app is compatible only with API 16 and above ?

2- to improve compatibility could I use inKeyguardRestrictedInputMode ?
But from the explanations (see here after), I cannot figure what is its purpose... Does it reflect the actual status of the screen lock whatever the status locked or not of the phone ? Or is it more or less the same as isKeyguardLocked which is true only when the phone is locked (my need) ?

Added in API level 1 <<<<<<< would be perfect !
If keyguard screen is showing or in restricted key input mode (i.e. in keyguard password emergency screen). When in such mode, certain keys, such as the Home key and the right soft keys, don't work.
Returns
  • true if in keyguard restricted input mode. <<<<<<<<< ????????
 
Upvote 0

aeropic

Active Member
Licensed User
Longtime User
I confirm, it seems inKeyguardRestrictedInputMode does the job.

To avoid this kind of mistake (forgetting to update the android manifest with the API version, is there a way to parse the code or so in order to automatically determine which is the minimum API level required to tun the application once compiled ?
 
Upvote 0

aeropic

Active Member
Licensed User
Longtime User
That makes sense that reflection is the developper responsibility...

For everything but reflection, could we imagine to decrease the value of targetted API in the manifest editor, compile and check for errors ? Would the compiler trigger an error ?
 
Upvote 0
Top