In my Android app, I use the following code to change the screen brightness
WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.screenBrightness = someValue; getWindow().setAttributes(lp);
It works fine on Android devices, but it doesn’t work when I transfer it to BlackBerry-10. Is there any other method I should use or a workaround?
Torcellitic solution (Anton Cherkashin):
I tried this, after further testing, it changes the brightness on the Android device, but not on the BlackBerry. The only reason this happens on BlakcBerry is the discovery of a new activity (activity change).
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);
soothers:
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);
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>
source share