2014-01-14 3 views
3

사실 내 신청서에는 액티비티이 있습니다. 알림을 만들려면 보류중인 활동 의도를 전달해야합니다. 하나의 활동에 대한 여러 알림

NotificationManager mgr=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
     Notification note=new Notification(mob.app.R.drawable.message,"Message!",System.currentTimeMillis()); 
     // This pending intent will open after notification click 
     PendingIntent i=PendingIntent.getActivity(this, 2,new Intent(this,SaleNotification.class),0); 


     note.setLatestEventInfo(activity,messageHeading,message, i); 

     //After uncomment this line you will see number of notification arrived 
     note.number=notifyNumber; 
     mgr.notify(0, note); 

여기 SaleNotification.class는 activity.It 간단한 클래스입니다하지 않습니다. 이 경우 하나 이상의 알림을 생성 할 수 있습니까? 미리 감사드립니다.

답변

8

별도의 알림을 받으려면 각기 다른 ID을 사용해야합니다.

이 간단한 예제입니다 : 다음

private int SIMPLE_NOTFICATION_ID_A = 0; 
private int SIMPLE_NOTFICATION_ID_B = 1; 

// display A 
displayNotification("Extra for A", "This is A", "Some text for activity A", MyActivityA.class, SIMPLE_NOTFICATION_ID_A); 
// display B 
displayNotification("Extra for B", "This is B", "Some text for activity B", MyActivityB.class, SIMPLE_NOTFICATION_ID_B); 

및 displayNotification : 작동

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); 
} 
+2

덕분에 ... – Sunny

+2

는 답변을 받아 항상 좋은 :) –

관련 문제