2012-07-26 70 views
0

我想每次我送notification.The以前通知得到由新one.I覆蓋觀看了其他問題,他們說已經通知的多個Id's才能收到我的mobile.But多個通知我也這樣做,但我不知道我哪裏出錯。發送多個通知androidle

以下是我創造我的通知。(這是在服務創建)。

private void GenerateNotification(String data) 
{ 
    String ns=Context.NOTIFICATION_SERVICE; 
    manager=(NotificationManager) getSystemService(ns); 

    int icon=R.drawable.ic_launcher; 
    long when = System.currentTimeMillis(); 

    Notification notification = new Notification(icon, data, when); 
    notification.flags |=Notification.FLAG_AUTO_CANCEL; 
    notification.defaults |= Notification.DEFAULT_SOUND; 
    Context context = getApplicationContext(); 
    CharSequence contentTitle = "The Best Essay"; 
    CharSequence contentText = data; 
    Intent notificationIntent = new Intent(this,MainActivity.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 
    manager.notify(HELLO_ID, notification); 
    HELLO_ID++; 
} 

其中HelloID增量來接收多個具有唯一id's的通知。請告訴我我在哪裏做錯了。

回答

0

所以,問題是,你正在使用的目的是每次都一樣。如果您嘗試使用與已顯示的通知中使用的Intent相同的Intent來通知用戶,則Android會將它們視爲重複項。這是因爲每次點擊通知最終會做同樣的事情(所以android就像「爲什麼我需要顯示其中的兩個?」)。

要做的事情是說「嗨,我是否已經顯示通知?如果是這樣,我將創建一個新的通知,將覆蓋當前的通知,但傳達的事實,實際上有兩件事情我正在通知「。考慮短信應用程序。當您收到第二條未讀短信時,它會覆蓋有關原始短信的第一條通知,並將其替換爲通知,告訴您有兩條新短信。合理?

+0

thnx.But我想表明單獨通知,因爲我會在該通知中所recieveing數據會幫我通知被點擊後,單獨在接下來的活動中顯示的數據很好的解釋。 – Mj1992 2012-07-26 16:46:03

+0

因此,在您的意圖存儲您需要的所有數據。然後讓你的活動把它整理出來。回到短信示例,如果需要顯示多條短信,通知會將您帶到所有未讀短信的列表,而不是特定的短信,然後讓您選擇要發送的短信你想先查看。日Thnx最好explanation.Do你已經在博客或東西,我很想 – 2012-07-26 16:48:47

+0

啊遵循它:) – Mj1992 2012-07-26 16:56:22