0

通知代码:

mNotificationManager = 
             (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    final Notification notifyDetails = 
            new Notification(R.drawable.ic_launcher,"New Alert, Click Me!",System.currentTimeMillis());
    Context context = getApplicationContext();
      notifyDetails.
    CharSequence contentTitle = "Notification Details...";

    CharSequence contentText = "Browse Android Official Site by clicking me";
    Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com"));

    PendingIntent intent1 = 
          PendingIntent.getActivity(this, 0, 
          notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
    notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent1);
    mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);

我的通知工作正常,我想要发生的是当通知弹出时屏幕亮度增加到一定值。

我使用 Eclipse 的自动完成功能来找到正确的功能,但没有任何作用。我也搜索了很多,没有运气。

我该如何解决这个问题?

4

1 回答 1

0

前段时间我也遇到过类似的亮度问题。看看这个答案。它应该为您指明正确的方向。

将此添加到您的活动中:

Settings.System.putInt(getContentResolver(),
                    Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 255);//255 here is your brightness value, an integer that can be between 0 and 255.
float brightness = 1.0f; //Your desired brightness, float value between 0.0 and 1.0
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);

并将此权限添加到 AndroidManifest.xml:

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

我刚刚对其进行了测试,此代码适用于 Android 4.1。

于 2013-01-15T06:13:08.080 回答