thanx Shai for the link

i solved the puzzle

here is the code which works
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.os.Build;

import java.io.IOException;

public class BrightImpl   { 

    
   
    public float brightset(int brightness ) {
 
        

      Context context = 
com.codename1.impl.android.AndroidNativeUtil.getContext();
                  // Check whether has the write settings permission or not.
                  
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
         
    
if(!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.WRITE_SETTINGS,
 
"Write settings denied")){
       return -100;
   
} else { 
   
         
     changeScreenBrightness(context, brightness );
     
     
     
     return 20;
     }
            

 
 } else {

                  
    
 
if(!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.WRITE_SETTINGS,
 
"Write settings denied")){
       return -100;
   
} else { 
   
         
     changeScreenBrightness(context, brightness );
     
     
     
     return 20;
     }
            
            
}}
   
    
   // 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);
       */
      
      
     Activity  myactivity = 
com.codename1.impl.android.AndroidNativeUtil.getActivity();
        Window window = myactivity.getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.screenBrightness = screenBrightnessValue / 255f;
        window.setAttributes(layoutParams);
        
 myactivity.getWindow().addFlags(WindowManager.LayoutParams.FLAGS_CHANGED);
    }
       

 
    
    public boolean isSupported() {
        return true;
    }

}



Op donderdag 7 november 2019 03:55:55 UTC+1 schreef Shai Almog:
>
> No. Native interfaces don't extend activity and it shouldn't work. It's a 
> different lifecycle.
> Native interfaces are objects we create. An activity is something the OS 
> needs to create. These are very different things. We create the native 
> CodenameOneActivity and provide you various tools to work with it e.g. 
> AndroidNativeUtils etc. see 
> https://www.codenameone.com/manual/advanced-topics.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 codenameone-discussions+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/ca747020-839a-4794-8dd8-36c99a8a0c23%40googlegroups.com.

Reply via email to