1

アプリがバックグラウンドのときにプッシュ通知を受信するだけです。アプリがプッシュを受け取ったときに正確に何が発生したのかわかりませんでした。通知メッセージが「hi」である場合の例として、通知本体を変更したいだけです。ユーザー「hi user」を表示したいとします。アプリがバックグラウンドのときにアンドロイドでfirebaseプッシュ通知を変更します。

public class MyFcmListenerService extends FirebaseMessagingService { 

    @Override 
    public void onMessageReceived(RemoteMessage message) { 
     //nothing triggered here when app is in background 
    } 

} 
+0

バックグラウンドでは、直接トリガーされます。メッセージを変更することはできません。サーバー側からの通知ペイロードにメッセージを設定する必要があります。アプリがバックグラウンドにあるときは、メインアクティビティまたはアクションアクティビティからインテントバンドルを使用してペイロードを処理できます。 –

+0

それをチェックアウトする[Firebaseのバックグラウンドでのアプリの通知を処理する方法](http://stackoverflow.com/a/37845174/3536264) –

+0

通知をどこから送信していますか?私は 'Firebase'コンソールかあなたのサーバーを意味しますか? Firebaseから通知を送信している場合は、オプションに進み、通知にデータを追加します。また、サーバーから送信する場合は、表示メッセージを送信しないでください(データメッセージのみを送信する)。 –

答えて

1
$fields = array(
'registration_ids' => $reg_id , 
'priority' => "high", 
'data' => array(******));  
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); 

私は同じ問題に直面しています。 PHP firebaseサービスから通知キーの値を削除しました。私の問題は解決しました。私はちょうどあなたは、あなただけの通知がアンドロイドでどのように機能するかをfirebaseプッシュ知っておく必要がありregistration_idsprioritydata

0

をすることができます使用しています。

あなたは

handleIntent機能を無効にする必要があります。

この機能はバックグラウンドでFirebase通知を処理します。その内部で、プッシュメッセージで送信されたすべてのデータをプッシュ通知にします。メッセージから情報を抽出することを忘れないでください。タイトルや本文などの既定のスペースを使用できますが、カスタムデータを送信することもできます。

次は、どのように動作するかのサンプルコードを添付します。

注:この方法を持っていないならば、あなたはどんな質問をして、私はマイルの答えを編集しますを持っている場合は10.0.1

public class MyFirebaseMessagingService extends FirebaseMessagingService { 
    private static final String TAG = "FCM Service"; 
    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     // TODO: Handle FCM messages here. 
     // If the application is in the foreground handle both data and notification messages here. 
     // Also if you intend on generating your own notifications as a result of a received FCM 
     // message, here is where that should be initiated. 
     Log.d(TAG, "From: " + remoteMessage.getFrom()); 
     Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); 
    } 

    @Override 
    public void handleIntent(Intent intent) { 
     //super.handleIntent(intent); 

     Log.d(TAG,"Handling Intent"); 
     Bundle mBundle = intent.getExtras(); 
     String img = mBundle.getString("imgURL"); 
     String title = mBundle.getString("gcm.notification.title"); 
     String body = mBundle.getString("gcm.notification.body"); 
     mBundle.putInt("promoId",Integer.valueOf(mBundle.getString("promoId"))); 
     Integer id = mBundle.getInt("promoId"); 

     sendNotification(mBundle); 
    } 

    private void sendNotification(Bundle mBundle) { 
     // Create an explicit content Intent that starts the main Activity. 
     Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); 

     notificationIntent.putExtras(mBundle); 

     // Construct a task stack. 
     TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 

     // Add the main Activity to the task stack as the parent. 
     stackBuilder.addParentStack(MainActivity.class); 

     // Push the content Intent onto the stack. 
     stackBuilder.addNextIntent(notificationIntent); 

     // Get a PendingIntent containing the entire back stack. 
     PendingIntent notificationPendingIntent = 
       stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 

     // Get a notification builder that's compatible with platform versions >= 4 
     NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 

     String title = mBundle.getString("gcm.notification.title"); 
     String body = mBundle.getString("gcm.notification.body"); 

     // Define the notification settings. 
     builder.setSmallIcon(R.mipmap.ic_launcher) 
       // In a real app, you may want to use a library like Volley 
       // to decode the Bitmap. 
       .setLargeIcon(BitmapFactory.decodeResource(getResources(), 
         R.mipmap.ic_launcher)) 
       .setColor(Color.RED) 
       .setContentTitle(title) 
       .setContentText(body) 
       .setContentIntent(notificationPendingIntent); 

     // Dismiss notification once the user touches it. 
     builder.setAutoCancel(true); 

     // Get an instance of the Notification manager 
     NotificationManager mNotificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

     // Issue the notification 
     mNotificationManager.notify(0, builder.build()); 
    } 

} 

よりfirebaseバージョンアップをアップグレードする必要があります。

関連する問題