繁体   English   中英

Nexus 5通知灯颜色

[英]Nexus 5 Notification Light Color

我正在使用Nexus 5(SDK 4.4.4),并且尝试发送一些颜色不同的通知。 我试图用一个简单的代码测试颜色:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    for (int i = 0; i < 8; i++) {
        notif.cancel(1); // clear previous notification
        final Notification notification = new Notification();
        if (i == 0){
            notification.ledARGB = Color.MAGENTA;
        }else if (i == 1){
            notification.ledARGB = Color.BLUE;
        }else if (i == 2){
            notification.ledARGB = Color.CYAN;
        }else if (i == 3){
            notification.ledARGB = Color.GRAY;
        }else if (i == 4){
            notification.ledARGB = Color.GREEN;
        }else if (i == 5){
            notification.ledARGB = Color.RED;
        }else if (i == 6){
            notification.ledARGB = Color.WHITE;
        }else if (i == 7){
            notification.ledARGB = Color.YELLOW;
        }
        notification.ledOnMS = 1000;
        notification.flags |= Notification.FLAG_SHOW_LIGHTS;
        notif.notify(1, notification);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

该代码应该发送8种不同的颜色通知。 我的手机实际要做的是复制蓝色,红色和洋红色3种颜色。 其余颜色似乎无效。

当然,其他颜色应该实际上可以工作,因为Light Flow应用程序成功发送了具有绿色等颜色的通知。

这可能是什么问题? 是否还有其他可能有效的代码?

您可以阅读以下内容: https : //developer.android.com/preview/notifications.html ,如果您在那看,您会发现Google不建议更改通知的颜色,他们建议使用透明颜色,我引用:

不要

使用颜色将您的应用与其他应用区分开。 通知图标只能是透明的白色背景图像。

-编辑-我的错误,我还没有看到您要更改led颜色,

但是,如果您只想更改led颜色,请尝试使用类似以下代码的代码: notification.ledARGB = 0xFFff0000; 为您想要的颜色。

我再次尝试编译该程序,然后找到了解决方案。

对于遇到相同问题的其他所有人,我多次运行该程序后,颜色开始显示,重新启动手机后,该程序现在可以正常运行了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM