Is it possible to modify the Android manifest file to prevent a program from sleeping, which apparently is currently done...
http://stackoverflow.com/questions/2039555/how-to-get-an-android-wakelock-to-work
I'll add this to V11. But if you manage to make it for V10, ppl will not be sad.
I've added android:keepScreenOn="true" to the manifest file, so I'll see if that works :)
<drumroll>...
No, didn't work unfortunately - the screen still went dark and then the device still was able to suspend.
Need to try a few other things now :)
Any idea where getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
could go ?
Think I found the place :)
This seems to work :
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
although the first code seems to also work fine...
Seems to work .. as in .. really works?
I'll be leaving it running for the next hour or so - and if the screen hasn't dimmed then it is working...
Great. I'll include that in V11 builds. Many thanks.
No problem - it works well!
Slightly old topic, but I thought it worth updating rather than creating a new one.
The above changes didn't work for me on various devices and I had to perform a few other changes to get it to work properly.
In summary, I had to employ the use of "wakelocks" by updating the AndroidManifest.xml and also updating SDLActivity.java. This allows us to enforce a full wake lock which prevents dimming and the eventual stand-by action.
I've already passed these changes on to Gernot for possible inclusion in a future GLB release. (Hi Gernot - krakatomato here!) :)
I haven't attached my SDLActivity.java file as I'm unsure as to the license implications (GLB free vs GLB pro) however, the changes are simple to include:
In AndroidManifest.xml, add the new permission:
<uses-permission android:name="android.permission.WAKE_LOCK"
e.g.:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<supports-screens android:resizeable="false"
In SDLActivity.java we need to make a few changes:
Add the following at the top of the file (anywhere after the class definition, but before the onCreate() method):
// Power management
PowerManager pm;
PowerManager.WakeLock wl;
e.g.:
// Audio
private static Thread mAudioThread;
private static AudioTrack mAudioTrack;
// Power management
PowerManager pm; // <<-- ADD THIS LINE
PowerManager.WakeLock wl; // <<-- ADD THIS LINE
// Load the .so
static {
System.loadLibrary("SDL");
System.loadLibrary("SDL_image");
System.loadLibrary("mikmod");
System.loadLibrary("SDL_mixer");
System.loadLibrary("SDL_ttf");
System.loadLibrary("main");
}
Within the onCreate() method we also need to ensure that FLAG_KEEP_SCREEN_ON is set (as mentioned in this thread):
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
We also need to add the following to the very end of the onCreate() function:
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLBTag");
wl.acquire();
And finally, we need to ensure we release/acquire the wakelock on certain events:
Within onPause(), add:
wl.release();
Within onResume(), add:
wl.acquire();
and within onStop(), add:
wl.release();
Don't think I've missed anything, and I apologise if this sounds complicated - it's not really - and it certainly works :)
//Andy