【发布时间】:2021-09-29 21:12:44
【问题描述】:
我已经通过关注 YouTube 视频实现了 firebase 推送通知,并且当应用程序在后台运行时它工作正常,但是当应用程序进入前台时它不会显示通知,但我可以在 logcat 中看到通知。
这是代码-
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
getFirebaseMessage(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
}
public void getFirebaseMessage(String title, String msg){
Log.d("abc", title);
Log.d("abc", msg);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "plasmatechannel")
.setSmallIcon(R.drawable.ic_baseline_notifications_active_24)
.setContentTitle(title)
.setContentText(msg)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true);
NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this);
managerCompat.notify(101 , builder.build());
}
}
【问题讨论】:
标签: android firebase push-notification