我使用Firebase消息傳遞服務來接收推送通知。 如果我的屏幕解鎖,一切都很好。Android:屏幕鎖定時,通知不會振動/發出聲音/閃爍燈光
當我的屏幕被鎖定時,我收到通知,但我的手機沒有發出任何聲音,沒有振動,燈光也沒有閃爍。
這是我的代碼來生成消息:
private void sendNotification(String messageBody, String messageTitle) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setLights(Color.CYAN, 1, 1)
.setPriority(Notification.PRIORITY_MAX)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
屏幕打開時它工作嗎? –