Android Notification LED doesn't use my Color

て烟熏妆下的殇ゞ 提交于 2020-01-12 05:31:07

问题


I'm trying to use a Notification that also uses the Notification LED on my S3, but for some reason the color will always be blue (I guess it's the default?). I tried to use different colors but nothing changes. Other apps (like Whatsapp, Gmail and Facebook have no problems with showing a different color light).

Notification.Builder noteBuilder = new Notification.Builder(context)
                .setAutoCancel(true)
                .setPriority(Notification.PRIORITY_DEFAULT)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle(ContentTitle)
                .setContentText(ContentText)
                .setLights(Color.YELLOW, 500, 500)
                ;

Intent noteIntent = new Intent(context,HoofdScherm.class);
PendingIntent notePendingIntent = PendingIntent.getActivity(context, 0, noteIntent, PendingIntent.FLAG_CANCEL_CURRENT);
noteBuilder.setContentIntent(notePendingIntent);

Notification note = noteBuilder.build();
note.ledARGB = Color.YELLOW;
NotificationManager mgr = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
mgr.notify(0,note);

回答1:


You need to make sure all the defaults are overridden by setting

notification.defaults = 0;




回答2:


Have a look on source below. Working perfectly on S3:

 NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(ctx)
                        .setPriority(Notification.PRIORITY_HIGH)
                        .setSmallIcon(getNotificationIcon())
                        .setColor(0xff493C7C)
                        .setContentTitle(ctx.getString(R.string.app_name))
                        .setContentText(msg)
                        .setDefaults(Notification.DEFAULT_SOUND)
                        .setLights(0xff493C7C, 1000, 1000)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(styledMsg));


来源:https://stackoverflow.com/questions/14953793/android-notification-led-doesnt-use-my-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!