2017-09-24 2 views
0

앱이 백그라운드 또는 포 그라운드에있을 때 알림을 얻으려고하고 firebase 콘솔에서 Android 앱 활동으로 데이터 페이로드를 보내려고하지만 응용 프로그램이 배경 알림을 클릭 할 때 앱이 포 그라운드에서 페이로드 데이터를 수신하지 않을 때 알림을 수신하지 않음

  • 에있는 응용 프로그램은 또한 전경
  • , 내가 키 "STR"로, 중포 기지 콘솔에서 얻고 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 또는 우편 배달부에서 데이터 페이로드를 보내고받을 필요가

    , 이 매력처럼 작동합니다 :)

    관련 문제