2015-02-05 44 views
0

我有一些片段(1,2,3,4,5),我创建了一个推送消息,在通知栏中显示一个NotificationMessage(NotificationManager)。我想要在NotificationMessage中“触摸”特定的片段时打开。我怎么能打开关于NotificationMessage的特定片段?

问题是我不知道我该怎么做,有一些方法发送推参数和接收后我得到这个参数并打开特定的片段?

一个例子,在WhatsApp中我有一个联系人,当这个联系人发送一条消息给我时,我触摸通知,并用这个联系人打开我的消息。

我该怎么办?

在我的SendNotification类下面,我打开了SplashView。该SplashView是一个活动,但我想开一个片段,例如Fragment3

public class SendNotification { 

    public SendNotification(Context context, String title, String tickerText, String message, String url) { 
     NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
     PendingIntent contentIntent; 

     Intent intentJogarComOponente = new Intent(context, SplashView.class); 
     Bundle bd = new Bundle(); 
     bd.putString("title",title); 
     bd.putString("description",message); 
     bd.putString("url",url); 
     intentJogarComOponente.putExtras(bd); 
     contentIntent = PendingIntent.getActivity(context, 0, intentJogarComOponente, PendingIntent.FLAG_UPDATE_CURRENT); 

     NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) 
       .setSmallIcon(R.drawable.ic_launcher) 
       .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) 
       .setTicker(tickerText) 
       .setContentTitle(title) 
       .setContentText(message); 

     mBuilder.setContentIntent(contentIntent); 

     if(!PushControl.getIsVisible()){ 
      Notification notification = mBuilder.build(); 
      notification.flags |= Notification.FLAG_AUTO_CANCEL; 
      notification.vibrate = new long[]{150, 300, 150, 600}; 
      mNotificationManager.notify(AndroidSystemUtil.randInt(), notification); 
     } 


    } 
} 

回答

0

添加

intentJogarComOponente .putExtra("started_from","notification"); 

to the code that starts the intent from the notifications, and the same thing 
to the other startActivity calls just change the value, then inside your 
activity 

String startedFrom = getIntent().getStringExtra("started_from"); 

,并检查它在你的活动,如果你正在做你希望的片段取代交易并开始GET你想要的片段。