Android Question Check to see if a Partiallock is set ?

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.
 

Jmu5667

Well-Known Member
Licensed User
See http://developer.android.com/reference/android/os/PowerManager.html#isInteractive() for more info about
Dont know how but this shouild be doneable with Reflection and/or Javaobject
This does not work, probably as I am not too familiar with jo and java.

B4X:
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
 

Jmu5667

Well-Known 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?
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 :)
 
Top