2017-02-28 10 views
1

私はfcmでヘッドアップ通知を実装しました。 アプリがfcm通知を受け取ると、アプリが実行されていると、画面上にヘッドアップ通知が表示されます。それは良い。アプリが実行されていないとヘッドアップ通知が表示されない理由

私のアプリがバックグラウンドであるか殺されている場合、ヘッドアップ通知は表示されません。 この問題を解決するにはどうすればよいですか? (たぶん私はFCM通知を受信したときに私のアプリが実行されている場合、MyFirebaseMessagingServiceはいい仕事だと思う。しかし、私のアプリがバックグラウンドまたは殺されている場合は、MyFirebaseMessagingServiceクラスは動作しません)

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     Map<String, String> data = remoteMessage.getData(); 
     sendNotification(remoteMessage); 
    } 

    private void sendNotification(RemoteMessage message) { 

     Intent push = new Intent(this, SplashActivity.class); 
     push.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
       | Intent.FLAG_ACTIVITY_CLEAR_TASK 
       | Intent.FLAG_ACTIVITY_NEW_TASK); 
     PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0, push, PendingIntent.FLAG_CANCEL_CURRENT); 
     NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this) 
       .setSmallIcon(R.drawable.ic_launcher) 
       .setWhen(System.currentTimeMillis()) 
       .setContentTitle("test") 
       .setContentText(message.getNotification().getBody()) 
       .setCategory(NotificationCompat.CATEGORY_MESSAGE) 
       .setVibrate(new long[] {0}) 
       .setDefaults(Notification.DEFAULT_ALL) 
       .setAutoCancel(true) 
       .setPriority(NotificationCompat.PRIORITY_HIGH) 
       .setContentIntent(fullScreenPendingIntent); 
     NotificationManager nm = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     nm.notify(1, builder.build()); 

    } 


} 

答えて

1

FCMメッセージの2種類があります利用可能です。

  1. 通知メッセージは、「表示メッセージ」と呼ばれることもあります。

  2. クライアントアプリケーションによって処理されるデータメッセージ。

通知メッセージは表示されません。あなたのアプリが実行されていない、または殺されていないとき。

以下のリンクをご確認ください。お手数ですが、

https://firebase.google.com/docs/cloud-messaging/concept-options

+0

私の問題は自分の間違いではないということですか? – Dennis

+0

はい、リンクを確認してください。いくつかのアイデアを得ることができます。 – Thirumalvalavan

+0

ありがとうございます。私はあなたが天使だと思う – Dennis

関連する問題