【发布时间】:2018-11-07 14:24:48
【问题描述】:
我有一个可以向用户发送通知的应用程序,但是由于新的 PlayStore 更新需要匹配 targetSdkVersion 26,因此通知不再起作用,错误 toast 无法在频道“null”上发布通知。有一些关于它的线程,但我没有得到解决方案。这是我实际的 FirebaseMessagingService 类:
public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String notification_title = remoteMessage.getNotification().getTitle();
String notification_message = remoteMessage.getNotification().getBody();
String click_action = remoteMessage.getNotification().getClickAction();
String from_user_id = remoteMessage.getData().get("from_user_id");
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(notification_title)
.setContentText(notification_message);
Intent resultIntent = new Intent(click_action);
resultIntent.putExtra("user_id", from_user_id);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
int mNotificationId = (int) System.currentTimeMillis();
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());
}
}
我需要进行哪些更改才能使其再次运行?如果它也适用于 sdk 24 以上的设备,那就太好了。
【问题讨论】:
标签: java android firebase firebase-cloud-messaging