【发布时间】:2019-04-17 12:50:39
【问题描述】:
我正在使用 firebase 处理推送通知。我可以收到通知 当我的应用程序关闭或在后台但我没有收到通知时 当我的应用程序正在运行时,请帮助我,这样即使我的应用程序正在运行,我也能收到通知
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
shownotifeaction(remoteMessage.getNotification().getBody());
}
public void shownotifeaction(String message) {
PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, Splash_Img.class), 0);
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle("Porwal")
.setContentText(message)
.setContentIntent(pi)
.setAutoCancel(true)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
}
}
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_name" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
【问题讨论】:
-
附上你的代码。
-
我建议您将代码包含在您的问题中。这将增加您获得帮助的机会,并减少您的问题被标记和关闭的机会。
-
使用数据消息,然后手动显示通知。
-
请发布您所做的代码
-
感谢大家的回复,我转达感谢
标签: android firebase push-notification