我拼命向我的應用程序添加通知功能,使通知LED閃爍。之後我所有的嘗試都沒有什麼工作......Android - LED通知不閃爍
這裏是我的代碼:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setLights(Color.BLUE, 200, 200)
.setContentTitle(remoteMessage.getData().get("title"))
.setContentText(remoteMessage.getData().get("body"))
.setColor(getColor(R.color.buttonBlueInactive))
.setSmallIcon(R.mipmap.ic_launcher);
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.notify(1, notification.build());
}
如果有人可以幫助,這將非常感激。
SOLUTION
對於那些誰,我有同樣的問題,有解決辦法:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setLights(Color.BLUE, 200, 200)
// Add the line bellow
.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS)
.setContentTitle(remoteMessage.getData().get("title"))
.setContentText(remoteMessage.getData().get("body"))
.setColor(getColor(R.color.buttonBlueInactive))
.setSmallIcon(R.mipmap.ic_launcher);
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.notify(1, notification.build());
}
儘量提高測試的定時器......從變化200到2000只是爲了測試是否改變一些東西。 – W0rmH0le
剛剛嘗試過,但它沒有工作.. –
好的。你至少得到了通知,對吧?只是不閃爍的LED? – W0rmH0le