In my Android application I am using the following code to change screen brightness
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = someValue;
getWindow().setAttributes(lp);
On Android devices it works fine, but it doesn't work when I port it to BlackBerry-10. Is there a different method I should use or a workaround?
Torcellite's solution (by Anton Cherkashyn):
I tried this, after further testing it does change brightness on Android device, but not on BlackBerry. The only reason why it is dimming on BlakcBerry is because of opening new activity (activity change dim).
In my activity:
Intent intent = new Intent(getBaseContext(), DummyBrightnessActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("brightness value", value[screenBrightness]);
getApplication().startActivity(intent);
Dummy:
public class DummyBrightnessActivity extends Activity{
private static final int DELAYED_MESSAGE = 1;
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if(msg.what == DELAYED_MESSAGE) {
DummyBrightnessActivity.this.finish();
}
super.handleMessage(msg);
}
};
Intent brightnessIntent = this.getIntent();
float brightness = brightnessIntent.getFloatExtra("brightness value", 0);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);
Message message = handler.obtainMessage(DELAYED_MESSAGE);
//this next line is very important, you need to finish your activity with slight delay
handler.sendMessageDelayed(message,1000);
}
}
Manifest:
<activity android:name=".DummyBrightnessActivity"
android:taskAffinity=".Dummy"
android:excludeFromRecents="true"
android:theme="@style/EmptyActivity"></activity>
styles.xml
<style name="EmptyActivity" parent="android:Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Toast</item>
<item name="android:background">#00000000</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorForeground">#000</item>
</style>