2016-11-24 31 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来回改变,如果活动已经打开

相关问题