Android Question Check to see if a Partiallock is set ?

Discussion in 'Android Questions' started by Jmu5667, Apr 2, 2015.

  1. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Hi All

    Is it possible to check if a PartialLock is set. I would like to do this programatically not set a flag in my app to say it has been done.

    Maybe some inline Java can do this ?

    Regards

    John.
     
  2. DonManfred

    DonManfred Expert Licensed User

    lemonisdead and Jmu5667 like this.
  3. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    lemonisdead and DonManfred like this.
  4. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    This does not work, probably as I am not too familiar with jo and java.

    Code:
    Sub is_wakelock_set() As Boolean

       
    Dim j As JavaObject
       
       
    Return j.InitializeStatic("android.os.PowerManager.WakeLock").RunMethod("isHeld",Null)

    End Sub
    This is the error, wanna help fix it :)

    java.lang.IllegalArgumentException: expected receiver of type android.os.PowerManager$WakeLock, but got java.lang.Class<android.os.PowerManager$WakeLock>
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
    at com.is.vitllinkSOS.mod_functions._is_wakelock_set(mod_functions.java:432)
    at com.is.vitllinkSOS.svc_gps._service_create(svc_gps.java:451)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at com.is.vitllinkSOS.svc_gps.onCreate(svc_gps.java:46)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2571)
    at android.app.ActivityThread.access$1600(ActivityThread.java:139)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:156)
    at android.app.ActivityThread.main(ActivityThread.java:4977)
    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:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
    java.lang.RuntimeException: Unable to create service com.is.vitllinkSOS.svc_gps: java.lang.RuntimeException: java.lang.IllegalArgumentException: expected receiver of type android.os.PowerManager$WakeLock, but got java.lang.Class<android.os.PowerManager$WakeLock>
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2593)
    at android.app.ActivityThread.access$1600(ActivityThread.java:139)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:156)
    at android.app.ActivityThread.main(ActivityThread.java:4977)
    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:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: expected receiver of type android.os.PowerManager$WakeLock, but got java.lang.Class<android.os.PowerManager$WakeLock>
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at com.is.vitllinkSOS.svc_gps.onCreate(svc_gps.java:46)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2571)
    ... 10 more
    Caused by: java.lang.IllegalArgumentException: expected receiver of type android.os.PowerManager$WakeLock, but got java.lang.Class<android.os.PowerManager$WakeLock>
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
    at com.is.vitllinkSOS.mod_functions._is_wakelock_set(mod_functions.java:432)
    at com.is.vitllinkSOS.svc_gps._service_create(svc_gps.java:451)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    ... 13 more
     
  5. DonManfred

    DonManfred Expert Licensed User

    As i wrote i did not know how to do that
     
  6. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    cool :)
     
  7. Jmu5667

    Jmu5667 Well-Known Member Licensed User

  8. Erel

    Erel Administrator Staff Member Licensed User

    Java will not help here as you need a reference to the instance used by B4A PhoneWakeState. Why don't you want to use a process global variable?
     
  9. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    I have a couple of services that are scheduled, sometimes they may run at the same time (no problem). I have been led to believe that a partial lock is not specific to a service, is this true ?

    All I want to do was allow each service to know whether or not to acquire a lock and/or release it. Am I over thinking this.....:rolleyes: BTW the the app is working perfectly now, This is not a bug but because of the nature of the app battery consumption cannot be an issue, and it is not now :)
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Yes.

    I think that you should use a code module to manage the partial lock. Then it will be simple to track its state.
     
    Jmu5667 likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice