当应用程序处于后台或未运行时,推送通知工作不正确。我正在使用FireBaseCloud消息发送推送通知。这是我的FirebaseMessageService:public class FireBaseMessageService extends FirebaseMessagingService {@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) {
Log.e("TAG", "From: " + remoteMessage.getFrom());
Log.e("TAG", "Notification Message Body: " + remoteMessage.getData().get("CardName")+" : "+remoteMessage.getData().get("CardCode"));
sendNotification(remoteMessage.getNotification().getBody());}private void sendNotification(String messageBody) {
Intent intent = new Intent(this, StartActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher_final)
.setContentTitle("Notification")
.setContentText(messageBody)
.setTicker("Test")
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}}所以问题是当App运行ticker显示得很好,并且通知带有默认声音,但是当应用程序处于后台或没有运行时,通知将不带任何声音和ticker不在状态栏中显示。为什么会发生这种事,我怎样才能解决呢?
- 3 回答
- 0 关注
- 445 浏览
添加回答
举报
0/150
提交
取消