kivy / python-for-android

Turn your Python application into an Android APK
https://python-for-android.readthedocs.io
MIT License
8.08k stars 1.8k forks source link

device doesnt go on sleep mode #969

Closed razzbee closed 7 years ago

razzbee commented 7 years ago

Hello I have successfully compiled and installed my kivy app on android 6 device , but the device doesnt go on sleep mode even though I havent enabled wake lock

I am using the master branch of kivy , python for android and buildozer. Thank you

KeyWeeUsr commented 7 years ago

Are you sure you haven't enabled it in Developer settings or in a similar OS settings? Don't you have it connected via USB or something? The basic app isn't able to make Android stay awake.

razzbee commented 7 years ago

the same happens even without usb attached , besides I havent enabled 'Stay Awake' mode in developers settings (Off)

KeyWeeUsr commented 7 years ago

Can you provide the APK and/or the code?

razzbee commented 7 years ago

let me send apk , do I upload it here?

razzbee commented 7 years ago

App Uploaded here : http://playslack.com/mediamate.apk

razzbee commented 7 years ago

I have opensourced the core part (as planned ) docs is not very good , but that should at least help. https://github.com/razzbee/kivy-android-webview

razzbee commented 7 years ago

any solution yet?

KeyWeeUsr commented 7 years ago

The apk seems corrupted for some reason, can't open it on both phone or pc. However, the code doesn't seem to have any issues with the lock itself. Have you tried it on some other device with higher/lower/same android version? Apparently if the apk is really corrupted, you'll need to paste here the AndroidManifest.xml file.

I still think it's something enabled on your device that forbids the phone to sleep.

razzbee commented 7 years ago

I have reuploaded the apk , http://playslack.com/mediamate.apk , again the app crashes for android version less than 4.4

KeyWeeUsr commented 7 years ago

Confirmed, yet I have no clue why. App doesn't use any related permission to wake lock (check manifest), I have no such option enabled and even the code seems to be correct. Webview bootstrap too.

Android 4.4.2

razzbee commented 7 years ago

okay , but about this launch crash on android < 4.4 , is there any solution to that?

KeyWeeUsr commented 7 years ago

Lowering minimal api for your app, otherwise I don't know. Logcat would be needed for the crash.

razzbee commented 7 years ago

I think te non sleep mode is not from my code , because I tried compiling hello world and had the same bug, tried on android 5 & 6 devices

razzbee commented 7 years ago

Well I figured out that this error happens with the sdl2 backend , pygame backend doesnt have this bug

KeyWeeUsr commented 7 years ago

@inclement I tested it with both pygame and sdl2 launchers + that testapp_setup:

any idea why? Webview isn't build upon sdl2, is it?

razzbee commented 7 years ago

I cant use the pygame bootstrap , app crashes randomly with the pygame bootstrap , Please is there a fix for sdl2 bootstrap??

razzbee commented 7 years ago

@inclement , @tito PLEASE can you investigate into this since its not only webview apps, any app I compile using the sdl2 bootstrap prevents device from entering sleep mode

FeralBytes commented 7 years ago

@razzbee, why not just have your program stop after a set amount of time? Then the device will do it's normal sleep routine. Also if you want the device to sleep and still want to do things then you should make a service. If you service has forefront priority with a icon in the menu you can also get rid of that using some pyjinus; I put some code for that into the wiki.

razzbee commented 7 years ago

I have posted a demo , you can test it, besides , have you tried the new toolchain with sdl2 bootstrap (using buildozer) : http://playslack.com/mediamate.apk

inclement commented 7 years ago

I've checked the wakelock defaults, but it does default to 0 as it should. I guess this depends on something slightly different, and I'll keep looking into it.

inclement commented 7 years ago

Perhaps https://github.com/kivy/python-for-android/blob/master/pythonforandroid/bootstraps/sdl2/build/src/org/libsdl/app/SDLActivity.java#L371 is the culprit.

inclement commented 7 years ago

It looks like this is the Android manifestation of SDL2's screensaver suspension by default, as described here. You can try setting the env var as explained there as a temporary workaround. I'll look at a proper fix sometime soonish.

razzbee commented 7 years ago

This might be a silly question to ask but any idea on how to set the ENV variable in my code ???

inclement commented 7 years ago

I was thinking it would be sufficient to add from os import environ; environ['SDL_VIDEO_ALLOW_SCREENSAVER'] = '1' at the top of your python file (before any other imports). On reflection I'm not sure if that is early enough, but it should be okay.

razzbee commented 7 years ago

Thank you, I will try it and give you the feedback

On 13 January 2017 at 18:12, Alexander Taylor notifications@github.com wrote:

I was thinking it would be sufficient to add from os import environ; environ['SDL_VIDEO_ALLOW_SCREENSAVER'] at the top of your python file (before any other imports). On reflection I'm not sure if that is early enough, but it should be okay.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kivy/python-for-android/issues/969#issuecomment-272507059, or mute the thread https://github.com/notifications/unsubscribe-auth/AC3Si_KxIKoGJe2bi2xMuiMJdXgpAr-5ks5rR76fgaJpZM4LVfpu .

inclement commented 7 years ago

I've just checked this myself, and adding this env var does allow the device to sleep properly. I'm looking at how this should be fixed fully in Kivy.