当前位置: 首页 > 知识库问答 >
问题:

如果应用程序位于后台,则Firebase通知无法正常工作[重复]

柳胜
2023-03-14
public class FcmMessagingService extends FirebaseMessagingService {

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    String message = remoteMessage.getNotification().getBody();

    Map<String, String> params = remoteMessage.getData();

    Bitmap remote_picture = null;
    remote_picture = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.logo);

    intent = new Intent(this, HomeDrawer.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent, PendingIntent.FLAG_ONE_SHOT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setContentTitle("Notification Title");
    notificationBuilder.setContentText(message);
    notificationBuilder.setSmallIcon(R.drawable.ic_notif);
    notificationBuilder.setLargeIcon(remote_picture);
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification noti = new Notification();
    noti = notificationBuilder.build();
    //notificationBuilder.setVibrate(new long[] { 1000, 1000});
    //notificationBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
    noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
    notificationManager.notify(0,noti);

    super.onMessageReceived(remoteMessage);
}
 intent = new Intent(this, HomeDrawer.class);

共有1个答案

钱嘉致
2023-03-14
"notification" : {
  "body" : "great match!",
  "title" : "Portugal vs. Denmark",
  "icon" : "myicon", // the name of the resource
  "sound" : "mySound"
}
 类似资料:
  • 我需要帮助。Firebase通知在后台不工作。这是我的代码:

  • null 我还试了一下: 关闭应用程序进程-&>;关闭设备-&>;打开设备电源-&>;发送通知。。。并且没有收到通知! 看起来firebase只有在设备启动了应用程序而不是100%关闭的情况下才能收到通知,我的意思是,只需用后退键关闭它而不是关闭应用程序进程。 这怎么可能呢?据推测,即使应用程序关闭,firebase也应该收到通知。 我正在Nexus5X和Android 8.0上进行测试,我使用的

  • 我面临推送通知的问题,我使用谷歌云消息, 我的问题是,我的应用程序处理一些缓存数据,我使用推送通知中的数据刷新缓存,因此当用户关闭应用程序(主页按钮向上滑动)并且应用程序收到推送通知时,它不会调用方法,因此,应用程序无法访问该通知的有效负载并更新缓存的数据。 那么,有没有办法做到这一点? 只有当用户点击通知并且应用程序通过方法获得通知时,才可以? 如果用户通过单击应用程序图标打开应用程序,我无法获

  • 当应用程序在后台时,如何更新包含数据负载的Firebase推送通知?有没有办法在通知中指定通知id给Firebase API? 完整的项目在github https://github.com/akshatashan/FireBaseCloudMessagingDemo中

  • 我正在使用Firebase云消息发送推送通知。 和: 在中声明: 问题是,当应用程序运行时,显示良好,通知带有默认声音,但当应用程序在后台或未运行时,通知没有任何声音,而不显示在状态栏中。 为什么会出现这种情况,我如何修复它?