How do I purchase PARTIAL_WAKE_LOCK in the Kivy app (Android)?

I am trying to purchase PARTIAL_WAKE_LOCK

for my kivy application. Basically this is a timer app, the timer should keep running in the background when the screen is off. Everything works fine except for the tracking lock. This is how I could implement it in python:

from jnius import autoclass

PythonActivity = autoclass('org.renpy.android.PythonActivity')
activity = PythonActivity.mActivity

Context = autoclass('android.content.Context')
PowerManager = autoclass('android.os.PowerManager')

pm = activity.getSystemService(Context.POWER_SERVICE)
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 'TAG')

wl.acquire()

      

The app works fine, but when the screen turns off it crashes. By applying

def on_pause(self):
    return True
def on_resume(self):
    pass

      

Method

doesn't help me because it stops the timer at the point where the screen turns off.

In my file buildozer.spec

I have:

android.permissions = WAKE_LOCK

      

When I install:

android.wakelock = True

      

i get only screen_bright_wakelock

but i need it partial_wakelock

.

+3


source to share


1 answer


I assume you have misunderstood WAKE_LOCK

here. By default, if you do not touch the application, the system will detect the phone as "Idle" and lock it.

If the user closes the screen, switches to another app, etc., WAKE_LOCK

it does nothing. Because at this point your application should be in the background and in sleep mode.



You need a service. The service can continue to run when the application is in the background, whether the screen is locked or not. And you need a link between your application and the service (an internal OSC might be fine, feel free to search the web for examples).

Or try to see if AlarmManager / Alarm from Android API might be ok with you (never tested).

+2


source







All Articles