該應用程序在關閉或後臺未收到通知。下面是處理通知的我的服務類。 只有當唯一的應用程序正在運行時,通知纔有效。未在後臺收到Firebase通知或關閉應用程序
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFMService";
Random random = new Random();
int NOTIFICATION_ID = random.nextInt(9999 - 1000) + 1000;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
sendNotification();
}
private void sendNotification() {
Intent intent = new Intent(this, NotificationDisplay.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_bouddha_icon)
.setContentTitle("Bouddha Meridian School")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}
}
如何發送通知控制檯或服務器? –