ฉันใช้ 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 สามารถส่งการแจ้งเตือนด้วยสีต่างๆ เช่น สีเขียว เป็นต้น
มีปัญหาอะไรที่นี่? มีรหัสอื่นที่สามารถใช้งานได้จริงหรือไม่?