2017-09-24 2 views
0

Also versuche ich Benachrichtigungen zu erhalten, wenn die App im Hintergrund oder im Vordergrund ist und versuche, Nutzdaten von der Firebase-Konsole an die Android App-Aktivität zu senden ich erhalte dieseKeine Benachrichtigung, wenn die App im Vordergrund ist und auch keine Nutzdaten empfängt, wenn auf die Benachrichtigung geklickt wird

  1. ich erhalte Benachrichtigung, wenn App im Hintergrund ist
  2. Nicht Empfang einer Benachrichtigung, wenn App im Vordergrund
  3. auch ist, datapayload, die ich von Feuerbasis Konsole bin immer, mit der Taste „str“, zeigt nicht in Aktivität

Bitte sagen Sie mir, wo das Problem ist und wie es gelöst wird.

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()); 
} 

Antwort

0

Nun, ich habe es gelöst :)

Sie müssen nur von REST-API oder Postman, Nutzdaten senden und Datenwerte in Java-Code erhalten, es wird wie Charm arbeiten :)

Verwandte Themen