2016-11-24 29 views
-1

我Firebasemessagingservice類代碼:如何打開片段上的推送通知點擊傳球意圖

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

我的片段BaseActivity代碼onCreate()方法:

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

     replacefragment code; 

    } 

這不起作用..

+0

請發帖替換片段代碼。並編輯問題,正確地提及它想要達到什麼 –

+0

有什麼問題,請問一個問題...看到[問]並解釋你的問題 – AxelH

+0

覆蓋您的活動中的'NewIntent()'方法並從它調用片段。 – Piyush

回答

2

您需要發送一個關鍵的意圖數據,並使用該密鑰檢查,並執行這樣的代碼

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

和再檢查一下上的活動像

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

     replacefragment code; 

    } 

還要檢查onIntent來回改變,如果活動已經打開

相關問題