2017-09-24 9 views
0

アプリがバックグラウンドまたはフォアグラウンドにあるときに通知を受け取ろうとしていて、Firebaseコンソールからアンドロイドアプリへのデータペイロード私は、アプリがバックグラウンド 通知をクリックしたときにアプリケーションがフォアグラウンドでもペイロードデータを受信して​​いないときに通知を受信しない

  • にあるときアプリは、また、フォアグラウンド
  • に私がキー「STR」と、firebaseコンソールから取得していますdatapayloadたときに通知を受けていない通知を受けています。この

    1. を取得しています、アクティビティに表示されていません

    問題がどこで解決されるのか教えてください。

    private static final String TAG = "FirebaseMessagingServic"; 
    
    public FirebaseMessagingService() { 
    } 
    
    String value = "0"; 
    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
        // Check if message contains a data payload. 
        if (remoteMessage.getData().size() > 0) { 
         Log.d(TAG, "Message data payload: " + remoteMessage.getData()); 
         value = remoteMessage.getData().get("str"); //key text in quotes 
    
        } 
        String title = remoteMessage.getNotification().getTitle(); //get title 
        String message = remoteMessage.getNotification().getBody(); //get message 
    
        sendNotification(title, message, value); 
        // Check if message contains a notification payload. 
        /* if (remoteMessage.getNotification() != null) { 
    
    
    
         Log.d(TAG, "Message Notification Title: " + title); 
         Log.d(TAG, "Message Notification Body: " + message); 
    
    
        }*/ 
    } 
    
    @Override 
    public void onDeletedMessages() { 
    
    } 
    
    private void sendNotification(String title,String messageBody, String value) { 
        Intent intent = new Intent(this, CS101noti.class); 
        SharedPreferences prefs = getSharedPreferences("MyApp", MODE_PRIVATE); 
        prefs.edit().putString("body", value).apply(); 
    
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, 
          PendingIntent.FLAG_ONE_SHOT); 
    
        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
          .setSmallIcon(R.mipmap.ic_launcher) 
          .setContentTitle(title) 
          .setContentText(messageBody) 
          .setAutoCancel(true) 
          .setSound(defaultSoundUri) 
          .setContentIntent(pendingIntent); 
    
        NotificationManager notificationManager = 
          (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    
        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); 
    } 
    
  • 答えて

    0

    まあ、私はそれを解決した:)

    をあなたはちょうどそれが魅力のように動作します 、REST APIまたは郵便配達からのデータペイロードを送信し、Javaコード内のデータ値を取得する必要があります:)

    関連する問題