在我的 Android 应用程序中,我使用以下代码来更改屏幕亮度
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = someValue;
getWindow().setAttributes(lp);
在 Android 设备上它工作正常,但是当我将它移植到 BlackBerry-10 时它不起作用。我应该使用其他方法或解决方法吗?
Torcellite 的解决方案(由 Anton Cherkashyn 提供):
我试过这个,经过进一步测试,它确实改变了 Android 设备上的亮度,但在 BlackBerry 上没有。它在 BlakcBerry 上变暗的唯一原因是因为打开了新活动(活动变化变暗)。
在我的活动中:
Intent intent = new Intent(getBaseContext(), DummyBrightnessActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("brightness value", value[screenBrightness]);
getApplication().startActivity(intent);
假:
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);
}
}
显现:
<activity android:name=".DummyBrightnessActivity"
android:taskAffinity=".Dummy"
android:excludeFromRecents="true"
android:theme="@style/EmptyActivity"></activity>
样式.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>