2011-12-22 17 views
1

的Android如何将数据传递到多个通知,明确当点击它

多个数据传递到通知 当我通知点击它只能打开最近

final Notification notifyDetails = new Notification(R.drawable.e4,"temp",System.currentTimeMillis()); 
        long[] vibrate = {100,100,200,300}; 
        notifyDetails.vibrate = vibrate; 
        notifyDetails.defaults =Notification.DEFAULT_ALL; 
        Context context = getApplicationContext(); 
        CharSequence contentTitle = "hello" 
        CharSequence contentText = "You have a notification" ; 
        Intent notifyIntent = new Intent(context, Send_Notification_Act.class); 
        notifyIntent.putExtra("name", "sunil"); 
        notifyIntent.putExtra("ID", SIMPLE_NOTFICATION_ID); 
        PendingIntent intent = 
        PendingIntent.getActivity(Back_Reciver.this, 0, 
        notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK); 
        notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent); 

回答

0
private NotificationManager mNotificationManager; 
private int SIMPLE_NOTFICATION_ID = 0; 
private int SIMPLE_NOTFICATION_ID_A = 1; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 

    Button quick = (Button) findViewById(R.id.quickbutton);   

    quick.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 

      displayNotification("Text", "Text", "Text", MyActivity.class,  SIMPLE_NOTFICATION_ID); 

      displayNotification("Text", "Text", "Text", MyActivityA.class, SIMPLE_NOTFICATION_ID_A); 
     } 
    }); 
} 

private void displayNotification(String extra, String contentTitle, String contentText, Class<?> cls, int id) {  
    Notification notifyDetails = new Notification(R.drawable.icon, "New Alert!", System.currentTimeMillis()); 
    Intent intent = new Intent(this, cls); 
    intent.putExtra("extra", extra); 
    PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), id, intent, PendingIntent.FLAG_ONE_SHOT); 
    notifyDetails.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent); 
    mNotificationManager.notify(id, notifyDetails); 
} 
相关问题