【问题标题】:Change brightness on Notification更改通知的亮度
【发布时间】:2012-12-29 05:07:03
【问题描述】:

通知代码:

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 的自动完成功能来找到正确的功能,但没有一个工作。我也搜了不少,没有运气。

我该如何解决这个问题?

【问题讨论】:

    标签: android notifications brightness


    【解决方案1】:

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

    将此添加到您的活动中:

    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 上运行。

    【讨论】:

    • 我不想通过虚拟活动来改变亮度。当我的应用收到通知时,我希望提高手机的亮度。
    • 所以不要使用虚拟活动部分,只需使用更改亮度的代码即可。它在里面。还是要我帮你复制粘贴到这里?
    • 您能告诉我如何通过通知更改亮度吗?使用代码,这将非常有帮助:)
    • 我意识到这是亮度编辑部分。之后我应该打电话通知吗?
    • 嗯,这取决于你想如何处理它。我会让它先显示通知,然后再改变亮度。但我想如果你以相反的顺序做它会同样有效。
    猜你喜欢
    • 2020-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 2012-10-10
    相关资源
    最近更新 更多