sleep mode ?!

hi all

is there a way to turn sleep mode off in android? o a way to control its timer programmatically?
I really need my app to run all the time (or at least 1 hr) and devices only allow for 10 mins max on the sleep mode timer

hope u can help me!

thanx!

.r

1 Like

In the coe Android / Java SDK, you would use a wake lock… I’m not sure if there’s a call to that from oFAndroid…

so if you include this in your manifest you can set system settings from the Main Activity:

  
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>  

you can do something like this to set the system settings

  
android.provider.Settings.System.putInt(getContentResolver(),android.provider.Settings.System.SCREEN_BRIGHTNESS, brightness);  

You can look over all the system settings you can set here:http://developer.android.com/reference/android/provider/Settings.System.html.

So you can set SCREEN_OFF_TIMEOUT and a few other things.

1 Like

actually once you’ve set the permission in the manifest you can call:

ofxAndroidLockScreenSleep();

and

ofxAndroidUnlockScreenSleep();

from c++ code to lock and unlock sleep

1 Like

thank you both!!
ofxAndroidUtils FTW!

* )
.r

A decade later.

How do I run that in my code?

I’m looking to do just that, change the screen brightness in app.

I don’t think you can do this anymore…

Ah k. thanks @DANtheMAN for your prompt response!

I managed to fumble my way through adding some new functionality to ofxAndroidUtils.

in OFAndroid.java

import android.provider.Settings;

static public void screenBrightness(int bri) {
	Context context = getContext();
	// code from here: https://www.geeksforgeeks.org/how-to-maximize-minimize-screen-brightness-programmatically-in-android/
	// Change the screen brightness change mode to manual.
	Settings.System.putInt(
			context.getContentResolver(),
			Settings.System.SCREEN_BRIGHTNESS_MODE,
			Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL
	);
	// Apply the screen brightness value to the system, this will change
	// the value in Settings ---> Display ---> Brightness level.
	// It will also change the screen brightness for the device.
	Settings.System.putInt(
			context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, bri
	);
}

in ofxAndroidUtils.h

void ofxAndroidScreenBrightness(int bri);

in ofxAndroidUtils.cpp

void ofxAndroidScreenBrightness(int bri)
{
	jclass javaClass = ofGetJavaOFAndroid();

	if (javaClass == 0)
	{
		ofLogError("ofxAndroidUtils") << "ofxAndroidScreenBrightness(): couldn't find OFAndroid java class";
		return;
	}

	jmethodID screenBrightness = ofGetJNIEnv()->GetStaticMethodID(javaClass, "screenBrightness", "(I)V");
	if (!screenBrightness)
	{
		ofLogError("ofxAndroidUtils") << "ofxAndroidScreeBrightness(): couldn't find OFAndroid screenBrightness method";
		return;
	}
	ofGetJNIEnv()->CallStaticVoidMethod(javaClass, screenBrightness, bri);
}