Change the brightness of the BlackBerry-10 screen from the Android application

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); //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> 
+4
source share
1 answer

While the code you are using changes the brightness of the current screen, the code I'm going to publish changes the brightness of the system.

 android.provider.Settings.System.putInt(getBaseContext() .getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, bright); 

Where bright is an integer value from 0 to 255.

This method will not update the screen brightness. Thus, you need to call an invisible action and close it to update the brightness of the screen.

Here is more info .

[EDIT]

Try adding this to your manifest:

 <uses-permission android:name="android.permission.WRITE_SETTINGS" /> 

[EDIT]

Try adding this too:

 <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" /> 
0
source

All Articles