2017-10-24 12 views
1

ブラウザで開いているFCMプッシュ通知でリンクを取得しています。私はこの方法でそれをやった:アプリが殺されたときにFCM通知をクリックするとブラウザが開きます

Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); 
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 

Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setContentTitle("Firebase Push Notification") 
      .setContentText(messageBody) 
      .setAutoCancel(true) 
      .setSound(defaultSoundUri) 
      .setContentIntent(contentIntent); 

NotificationManager notificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

notificationManager.notify(0, notificationBuilder.build()); 

しかし、問題は、通知のクリックでは、アプリケーションがフォアグラウンドにあるときにのみ開いているブラウザです。しかし、アプリが殺されたり、バックグラウンドでブラウザが開かれたりすると、アプリが開かれます。 PendingIntent.getActivity

答えて

0

あなたのアプリがバックグラウンドとFCMプッシュ通知である で

0

使用するアプリケーション・コンテキストは、要求内のnotificationペイロードが含まれています。その後、onMessageReceivedメソッドはトリガしないので、ブラウザは開かれません。

アプリがフォアグラウンドでないときにブラウザを開くには、通知リクエスト(郵便配達で試してみる)を送信する際に次の構文を使用する必要があります。リクエストの上

{ 
    "to": "device token", 
    "priority" : "normal", 
    "data":{ 
    "title": "title", 
    "body": "body" 
    } 

} 

、すなわち

{ 
    "to": "device token", 
    "priority" : "normal", 
    "notification":{ }, 
    "data":{ 
    "title": "title", 
    "body": "body" 
} 
} 
notificationペイロードフィールドを含むべきではありません
関連する問題