Android Question Unable to Unlock Screen with USB Accessory

floatingpoint

Member
Licensed User
Longtime User
Hi All,

I'm back onto the B4A work and fine tuning my USB accessory app.

Embedded host provides USB Accessory data to Android 4.1.2 device which is the display and control device.

Everything works well apart from swipe screen unlock. (Swipe is min lock level on this device)
USB comms will wake-up Android device and appears to invoke my app but it is hidden behind the swipe lock screen. (Of course manual swipe works but I would llke app to auto boot and display with no manual intervention)

No luck with:
B4X:
Sub SetShowWhenLocked
  Dim r As Reflector
  r.Target = r.GetActivity
  r.Target = r.RunMethod("getWindow")
  r.RunMethod2("addFlags", 6815872, "java.lang.int")
End Sub

In fact I get a null pointer error when 1st line executes.

Found this:
B4X:
    'http://www.androidsnippets.com/disable-initial-screen-lock
    'KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
    'KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    'lock.disableKeyguard();
   
    'In androidmanifest:
    ' <uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>

Are these methods/ classes accessible via B4A?

All suggestions welcome

FP
 

floatingpoint

Member
Licensed User
Longtime User
Can you post the full error message?

You can use the code posted here: http://www.b4x.com/android/forum/threads/locking-phone.17196/#post-110730

Make sure to add the permission with the manifest editor: AddPermission(android.permission.DISABLE_KEYGUARD)


Firstly, thank you Erel, KeyguardManager method works well.

Secondly, error due to 1st method below:

B4X:
usbservice_setshowwhenlocked (B4A line: 676)
r.Target = r.GetActivity
java.lang.NullPointerException
    at anywheresoftware.b4a.agraham.reflection.Reflection.GetActivity(Reflection.java:661)
    at b4a.p310_l7_a412_v103.usbservice._setshowwhenlocked(usbservice.java:919)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:834)
    at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:785)
    at b4a.p310_l7_a412_v103.pagehome._activity_create(pagehome.java:270)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at b4a.p310_l7_a412_v103.pagehome.afterFirstLayout(pagehome.java:89)
    at b4a.p310_l7_a412_v103.pagehome.access$100(pagehome.java:16)
    at b4a.p310_l7_a412_v103.pagehome$WaitForLayout.run(pagehome.java:74)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4929)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
    at dalvik.system.NativeStart.main(Native Method)

FP
 
Upvote 0
Top