2016-11-24 2 views
-1

My Firebasemessagingservice Klassencode für das Bestehen Absicht:Wie Fragment auf Klick von Push-Benachrichtigung öffnen

private void showNotification(String message){ 
    Intent intent=new Intent(this, DrawerActivity.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    intent.putExtra("data", message); 
    PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.Builder builder=new NotificationCompat.Builder(this) 
      .setAutoCancel(true) 
      .setContentTitle("Registry") 
      .setContentText(message) 
      .setSmallIcon(R.drawable.com_facebook_button_send_icon_blue) 
      .setContentIntent(pendingIntent); 
    NotificationManager manager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    manager.notify(0,builder.build()); 
} 

Mein Fragment BaseActivity Code in onCreate() -Methode:

Intent notifyIntent = getIntent(); 
    Bundle extras = notifyIntent.getExtras(); 
    if (extras != null) { 

     replacefragment code; 

    } 

Es funktioniert nicht ..

+0

pls post ersetzen Fragment-Code auch. Und bearbeiten Sie Frage, um es richtig zu erwähnen, was Sie erreichen möchten –

+0

Was ist das Problem, stellen Sie bitte eine Frage ... sehen Sie [fragen] und erklären Sie Problem – AxelH

+0

Überschreiben Sie 'NewIntent()' Methode in Ihrer Tätigkeit und rufen Sie Fragment von ihm auf. – Piyush

Antwort

2

Sie benötigen einen Schlüssel mit der Absicht, Daten zu senden und mit diesem Schlüssel überprüfen und Code ausführen wie

private void showNotification(String message){ 
    Intent intent=new Intent(this, DrawerActivity.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    intent.putExtra("data", message); 
    intent.putExtra("KEY", "YOUR VAL"); 
    PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.Builder builder=new NotificationCompat.Builder(this) 
      .setAutoCancel(true) 
      .setContentTitle("Registry") 
      .setContentText(message) 
      .setSmallIcon(R.drawable.com_facebook_button_send_icon_blue) 
      .setContentIntent(pendingIntent); 
    NotificationManager manager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    manager.notify(0,builder.build()); 
} 

und chech auf Aktivität wie

Intent notifyIntent = getIntent(); 
    String extras = getIntent().getExtraString("KEY");; 
    if (extras != null&&extras.equals("YOUR VAL")) {`enter code here` 

     replacefragment code; 

    } 

überprüfen onIntent auch fro ändern, wenn Aktivität bereits geöffnet ist

Verwandte Themen