Push notification 推送通知在API的后台不起作用<=25
我试图显示一个通知类型,它可以正常工作,但我只在API上得到通知Push notification 推送通知在API的后台不起作用<=25,push-notification,Push Notification,我试图显示一个通知类型,它可以正常工作,但我只在API上得到通知 @Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); PendingIntent pendingIntent = PendingIntent.getActivity( this
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
PendingIntent pendingIntent = PendingIntent.getActivity(
this, 0, new Intent(this, MainActivity.class), PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.notification_channel_id))
.setSmallIcon(R.drawable.ic_stat_notify)
.setContentTitle(getString(R.string.app_name))
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notify))
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE)
.setDefaults((NotificationCompat.PRIORITY_MAX))
.setContentIntent(pendingIntent);;
((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(remoteMessage.hashCode(), builder.build());
}