fcm通知不会在后台显示通知弹出窗口

uoifb46i  于 2021-09-29  发布在  Java
关注(0)|答案(2)|浏览(448)

我正在使用firebase云功能在我的应用程序中显示通知,而我面临的唯一问题是当应用程序关闭或后台通知未显示弹出窗口时。应用程序中使用了提醒通知,我确实收到了通知,但通知不会像应用程序在前台时那样弹出。我已将频道和通知的优先级设置为高,但仍然不起作用。
我的服务级别:

  1. @Override
  2. public void onMessageReceived(RemoteMessage remoteMessage) {
  3. super.onMessageReceived(remoteMessage);
  4. Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message"));
  5. Intent intent = new Intent(this, WebViewActivity.class);
  6. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  7. PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
  8. String channelId = "Default";
  9. NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
  10. .setSmallIcon(R.drawable.app_logo)
  11. .setContentTitle(remoteMessage.getNotification().getTitle())
  12. .setContentText(remoteMessage.getNotification().getBody())
  13. .setAutoCancel(true).setContentIntent(pendingIntent)
  14. .setDefaults(DEFAULT_SOUND | DEFAULT_VIBRATE)
  15. .setPriority(Notification.PRIORITY_MAX);
  16. NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  17. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  18. NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_HIGH);
  19. channel.setShowBadge(true);
  20. channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
  21. manager.createNotificationChannel(channel);
  22. }
  23. manager.notify(0, builder.build());
  24. }

显示

  1. <application
  2. android:allowBackup="true"
  3. android:icon="@mipmap/ic_launcher"
  4. android:label="@string/app_name"
  5. android:roundIcon="@mipmap/ic_launcher_round"
  6. android:supportsRtl="true"
  7. android:theme="@style/AppTheme">
  8. <activity android:name="com.noderon.riscalert.WebViewActivity">
  9. <intent-filter>
  10. <action android:name="android.intent.action.MAIN" />
  11. <category android:name="android.intent.category.LAUNCHER" />
  12. </intent-filter>
  13. </activity>
  14. <activity android:name="com.noderon.riscalert.MainActivity">
  15. </activity>
  16. <service
  17. android:name=".NotificationService">
  18. <intent-filter>
  19. <action android:name="com.google.firebase.MESSAGING_EVENT"/>
  20. </intent-filter>
  21. </service>
  22. </application>

任何帮助都将不胜感激。谢谢

8wigbo56

8wigbo561#

我也面临同样的问题。我遵循了firebase的官方文档,现在通知工作正常。点击这个链接。

qgelzfjb

qgelzfjb2#

您是否在活动中创建了firebasemessage示例()?

相关问题