2017-12-25 4 views
0

Ich habe versucht, eine benutzerdefinierte Farbe für die Benachrichtigung LED mit ARGB Farben einzustellen.Android Studio: Benutzerdefinierte Farbe auf Benachrichtigung LED mit ARGB funktioniert nicht

NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
Notification notification = new Notification.Builder(this) 
     .setDefaults(0) 
     .setTicker("") 
     .setSmallIcon(R.drawable.maxapplogo) 
     .setContentTitle("Notification") 
     .setContentText("This is a notification test!") 
     .setAutoCancel(true) 
     .setVibrate(new long[] { 1000, 500, 1000, 500, 1000 }) 
     .setLights(Color.GREEN, 1000, 1000) 
     .build(); 

/* notification.ledARGB = 0xffffee05; */ 

/* here I wanted to know if the int values of the color can help me */ 
int black = Color.BLACK; 
Log.d("black color", String.valueOf(black)); // -16777216 

int green = Color.GREEN; 
Log.d("green color", String.valueOf(green)); // -16711936 

int red = Color.RED; 
Log.d("red color", String.valueOf(red)); // -65536 

notification.flags = Notification.FLAG_SHOW_LIGHTS; 

if(notificationManager != null) { 
    notificationManager.notify(0, notification); 
} else { 
    Toast.makeText(getApplicationContext(), "Notification failed", Toast.LENGTH_SHORT).show(); 
} 

Wenn ich die Farbe mit dem Befehl COLOR.GREEN oder einer anderen verfügbaren Farbe einstelle, wird es funktionieren. Aber mit der ARGB-Spezifikation funktioniert es nicht. Es zeigt immer die gleiche Farbe auch mit verschiedenen ARGB-Farben.

Ich habe meine App auf einem Samsung Galaxy S8 getestet. Ich habe kein anderes Smartphone zum Testen. Hat jemand eine Idee, warum das nicht funktioniert? Es sollte laut anderen Stackoverflow-Beiträgen sein.

Antwort

0

FLAG_SHOW_LIGHTS und Notification.Builder.setLights (int, int, int); da Android O (API-Ebene 26)

Sie müssen verwenden Benachrichtigungskanal

NotificationChannel mChannel = new NotificationChannel(id, name, importance); 

mChannel.enableLights(true); 
// Sets the notification light color for notifications posted to this 
// channel, if the device supports this feature. 
mChannel.setLightColor(Color.RED); 
+0

Das Problem mit NotificationChannel ist, dass es Arbeit für ältere Versionen tut sind veraltet. – Max

+0

Verwenden Sie dies, wenn sdk> 23 für andere den Notification Manager verwenden – Hangman

Verwandte Themen