thanx i have changed the code but it is still not working on my device
my device is LG4c with android 5.0
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.Manifest;
import android.view.View;
import android.view.WindowManager;
import android.app.Activity;
import android.view.Window;
import com.codename1.impl.android.AndroidNativeUtil;
import android.app.AlertDialog;;
public class BrightImpl extends Activity {
public void brightset(int brightness ) {
try {
Context context = getApplicationContext();
// Check whether has the write settings permission or not.
if
(!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.WRITE_SETTINGS,
"permission asked ")) {
new AlertDialog.Builder(context)
.setMessage("Geen permission")
.setPositiveButton(android.R.string.ok, null)
.show();
} 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);
getWindow().addFlags(WindowManager.LayoutParams.FLAGS_CHANGED);
}
public boolean isSupported() {
return false;
}
}
Op maandag 28 oktober 2019 04:04:02 UTC+1 schreef Shai Almog:
>
> It looks like you're working with really old Android samples. You need to
> make sure your native code works on a modern device, it's very possible
> this is no longer accessible to the app.
> Modern Android devices require runtime permissions too see:
> https://www.codenameone.com/blog/marshmallow-permissions-in-the-simulator-and-native-code.html
>
--
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/13a6ab99-f477-4b68-8e3c-436925ce885b%40googlegroups.com.