0

I want to create a plugin that connect to javascript while using cordova for the plugin, this is my javascipt code :

var Brightness = function() {};

Brightness.prototype.brightnessUp = function( success, error ) 
{
    return cordova.exec( success, error, "Brightness", "brightnessUp", [] );
};

and my plugin code :

public PluginResult execute(String action, JSONArray data, String callbackId) {
    PluginResult result = null;
    if(action.equals(BRIGHTNESS_UP)){
        lightUP();
        result = new PluginResult(Status.OK);
    }

    return result;
}

public void lightUP(){
    WindowManager.LayoutParams layoutParams = cordova.getActivity().getWindow().getAttributes();
    layoutParams.screenBrightness = 1.0f;
    cordova.getActivity().getWindow().getAttributes().screenBrightness = 1.0f;
    cordova.getActivity().getWindow().setAttributes(layoutParams);
    cordova.getActivity().getWindow().addFlags(WindowManager.LayoutParams.SCREEN_BRIGHTNESS_CHANGED);
}

Somehow I don't know why the "setAttributes(layoutParam)" doesn't make any changed to the brightness screen in my application.

Accidentally when I press the home button, and go back to the application, suddenly the screen brightness changed according to the layoutParams.

Is there any solution for this?

1 Answers1

0

What you have is correct up until a point. You'll need to start a dummy activity right after you set the brightness in order for the change to take affect. Take a look at this SO answer:

https://stackoverflow.com/a/7658364/41679

Community
  • 1
  • 1
Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74