0
我想在我的應用中使用Firebase雲消息傳遞來獲取通知。如何在應用關閉時使用Firebase雲消息傳遞通知
我收到通知時,應用程序是在前臺或後臺,但如果應用程序被殺死,那麼它不起作用。我知道,如果沒有在關閉應用程序後運行服務之類的服務,這是不可能的,但我不知道如何實現它。
請指導我。提前致謝。
我正在使用這個類來獲取通知。
public class FcmMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String title= remoteMessage.getNotification().getTitle();
String message= remoteMessage.getNotification().getBody();
Intent intent= new Intent(this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent= PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder= new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(message);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager= (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,notificationBuilder.build());
}
}
[Android應用程序不接受火力地堡通知的可能的複製,當應用程序從多停止任務托盤](https:// stackove rflow.com/questions/39504805/android-app-not-receiving-firebase-notification-when-app-is-stopped-from-multi-t) –