Android Android屏幕亮度设置

(转载)http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2013/0222/889.html

求教关于Android屏幕亮度调节的问题,屏幕亮度分两种,一种是系统的,一种是局限于应用内的,我希望是应用内的调节即可,一款读书软件。

现在有这么几种思路,也是在网上找的,居然都不可以,不知道为什么

一种是

1
2
3
4
5
1. private void brightnessMax() {
    2. WindowManager.LayoutParams lp = getWindow().getAttributes();
    3. lp.screenBrightness = 1.0f;
    4. getWindow().setAttributes(lp);
    5. }

再详细一点是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
public class MyActivity extends Activity {
         /** Called when the activity is first created. */
         TextView textView;
  
         @Override
         public void onCreate(Bundle savedInstanceState) {
                 super .onCreate(savedInstanceState);
                 setContentView(R.layout.main);
                 textView = (TextView) findViewById(R.id.MyTextView);
                 updateToggles();
         }
  
         private void updateToggles() {
                 // TODO Auto-generated method stub
                 SeekBar seekBar = (SeekBar) findViewById(R.id.MySeekBar);
                 seekBar.setProgress((int) (android.provider.Settings.System.getInt(
                                 getContentResolver(),
                                 android.provider.Settings.System.SCREEN_BRIGHTNESS, 255) ));
                 seekBar.setOnSeekBarChangeListener(seekListener);
         }
  
         private OnSeekBarChangeListener seekListener = new OnSeekBarChangeListener() {
  
                 public void onProgressChanged(SeekBar seekBar, int progress,
                                 boolean fromUser) {
                         if (fromUser) {
                                 Integer tmpInt = seekBar.getProgress();
                                 System.out.println(tmpInt);
                                 // 51 (seek scale) * 5 = 255 (max brightness)
                                 // Old way
                                 android.provider.Settings.System.putInt(getContentResolver(),
                                                 android.provider.Settings.System.SCREEN_BRIGHTNESS,
                                                 tmpInt); // 0-255
                                 tmpInt = Settings.System.getInt(getContentResolver(),
                                                Settings.System.SCREEN_BRIGHTNESS, -1);
                                 // Cupcake way..... sucks
                                 WindowManager.LayoutParams lp = getWindow().getAttributes();
                                 // lp.screenBrightness = 1.0f;
                                 // Float tmpFloat = (float)tmpInt / 255;
                                 if (0<= tmpInt && tmpInt <= 255) {
                                         lp.screenBrightness = tmpInt;
                                 }
                                  
                                  
                                 getWindow().setAttributes(lp);
                         }
  
                 }
  
                 @Override
                 public void onStartTrackingTouch(SeekBar seekBar) {
                         // TODO Auto-generated method stub
                         // put awesomeness here
                 }
  
                 @Override
                 public void onStopTrackingTouch(SeekBar seekBar) {
                         // TODO Auto-generated method stub
                         // and here too
                 }
         };
}这是主程序

http://stackoverflow.com/questions/4544967/get-preferred-screen-brightness-in-android

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值