i tried the native interface but no luck, i dont got any error messages.
but the screen is not dimmed
i put the permission in build hints
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
this is my code
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.view.WindowManager;
import android.app.Activity;
import android.view.Window;
public class BrightImpl extends Activity {
public void brightset(int brightness ) {
try {
Context context = getApplicationContext();
// Check whether has the write settings permission or not.
boolean settingsCanWrite =
hasWriteSettingsPermission(context);
// If do not have then open the Can modify system settings panel.
if(!settingsCanWrite) {
changeScreenBrightness(context, brightness);
}else {
changeScreenBrightness(context, brightness);
}
} catch (Exception e) {}
}
// This function only take effect in real physical android device,
// it can not take effect in android emulator.
private void changeScreenBrightness(Context context, int
screenBrightnessValue)
{
// 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, screenBrightnessValue);
//refreshes the screen
/* int br = Settings.System.getInt(context.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = (float) screenBrightnessValue / 255;
getWindow().setAttributes(lp);
*/
Window window = getWindow();
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.screenBrightness = screenBrightnessValue / 255f;
window.setAttributes(layoutParams);
}
// Check whether this app has android write settings permission.
private boolean hasWriteSettingsPermission(Context context)
{
boolean ret = true;
// Get the result from below code.
ret = Settings.System.canWrite(context);
return ret;
}
public boolean isSupported() {
return false;
}
}
Op zondag 27 oktober 2019 12:33:56 UTC+1 schreef Peter Bell:
>
> Hi Shai
>
>
> No I want to save battery’. My gps app runs for hours.
> Do you know a native way, do you have some code?
>
>
>
>
> Op zondag 27 oktober 2019 04:04:10 UTC+1 schreef Shai Almog:
>>
>> Hi,
>> we don't have an API for that. You can probably use native interfaces to
>> do that but it's not something apps normally do as it's normally controlled
>> by device sensors.
>> Are you just trying to disable the screensaver?
>>
>
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/ddccbbf2-9d65-4864-b3f2-4d95f2b36bc7%40googlegroups.com.