cocos2dx android app doesn't lock the screen after inactivity - android

I ported my Cocos2dx game from iOS to Android. Everything works fine, but there is something strange on lock screen on android. The application doesn't lock the screen after inactivity.
I try to change SCREEN_OFF_TIMEOUT programmatically from my app. It changes, but not to my application.
I found on stackoverflow tips on calculating idle time, and then lock the screen programmatically. Is the only way? Is the screen should not be blocked automatically?

Hi try to call method setKeepScreenOn(false) in your cocos2d-x activity, which call method in Cocos2dxActivity.java This will allow game to sleep. After some time, if you have screen lock set in your phone settings will lock the screen.
setKeepScreenOn(true) function that prevent phone to sleep, useful for some
games

Related

Cordova/Ionic2 | How to lock and unlock Screen of Android and iOS?

I just want to find a plugin that can trigger the native device screen lock button.
So for example if you click a button your device gets locked just it would do if you click your devices native lock button on the side of the phone. For example if your lock button of the device is broken you could do this within an app.
As far as I can tell the only plugin that would work is this one:
https://github.com/kitolog/cordova-plugin-screen-locker . But it seems it only works for android (And might aswell only lock the screen orientation).
window.screenLocker.unlock(successCallback, errorCallback, 10); // 10 seconds unlock timeout (third parameter is optional)
window.screenLocker.lock(successFun, errorFun); // release screen unlock
Is there any solution for iOS aswell? I really cant find anything.
There is a very good reason why the plugin is android-only, as there is no public API to lock the screen on iOS. In general, Apple is more restrictive as to what it allows its developers to do.
For a more in depth explanation, check out this answer.

Android kills GL context when screen is locked

I have set mView.setPreserveEGLContextOnPause(true); and this works in most situations, but I recently noticed that if I lock the phone it kills the GL Context. The rest of the app seems to stay intact. I'm able to quit to the home screen and play another game, and go into the multitasker and still have my game waiting for me how I left it.
I have also found that if I go to the home screen and then lock the phone, the context is still intact. There is only a problem when I lock when inside the app.
Any help would be greatly appreciated.

What happens at Screen Lock?

I am working with Camera API to develop an android app. I use flash in this app and I need it to be ON all the time. I managed to turn flash ON at start, and after onResume() is called, but I can't figure out what to do after a screen lock. When I lock my screen and then unlock it, flash doesnt turn ON.
I need to understand how to manage that and turn flash ON after unlocking the screen if the app is running(not onPause()).
Any reference or advice is welcome! Thanks in advance!

How to turn off screen with smart lock Lollipop Pogramatically

Is there any way to lock the phone or turn the screen off and make it work with smart lock the next time I turn it on?
If I turn it off programatically the next time that I turn on the screen it dosen't start any smart lock process and looks like I didn't have the smart lock on.
Thanks
You can't do that currently. Using DevicePolicyManager.lockNow() to turn off the screen and lock the device crashes the GoogleTrustAgent. There is an open issue for this bug at the Android Open Source Project see Issue 79735. Hope it will be fixed soon.

Turn off device screen (without locking it)?

I'm making an app that uses the Proximity Sensor while a phone call is in progress. My main issue is that the device doesn't turn the screen off when I hold it up against my face (while talking on the phone). If anyone has a solution as to how to fix this, then my problem will be solved.
Right now though, I'm trying to manually switch the screen off to imitate the normal behavior of the phone app. I looked through a lot of other posts about this but most of them seem to have instructions on how to keep the screen turned ON. My case is the exact opposite... how do I programmatically set the device to turn it's screen off? I don't want it to lock itself or sleep (since the phone call will still be in progress), just turn the screen completely off.
Thanks!

Categories

Resources