2011-01-11 79 views
1

我在我的應用程序中遇到了通知圖標的一個奇怪問題。Android開發通知圖標問題

我的應用程序通過藍牙發送和接收數據。當應用程序啓動時,它會創建應用程序(icon.png)的通知圖標。然後它會看到沒有藍牙設備連接並將圖標更改爲(warn.png)。問題是,當頂部的狀態欄顯示warn.png時,在正在進行的通知下拉菜單中,它具有原始圖標(icon.png)和文本「無藍牙設備已連接」。當藍牙設備連接時,狀態欄圖標變回原始圖標(icon.png),但在正在進行的通知中,它具有帶有「連接建立」消息的警告圖標。

下面是我使用的代碼:

private void notification_updates(String DISPLAY_TEXT, String ONGOING_TEXT, int ICON) { 
Intent intent = new Intent(this,GUI.class); 
intent.addFlags(intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_SINGLE_TOP); 

try 
{ 
    notification.setLatestEventInfo(Monitor.this, "App_Name",ONGOING_TEXT, 
      PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); 
    notification.icon = ICON; 
    notification.tickerText = DISPLAY_TEXT; 
    notification.flags = notification.FLAG_ONGOING_EVENT; //on going events 
    notification.flags += notification.FLAG_NO_CLEAR; //no clear. 

    mManager.notify(APP_ID, notification); 

} catch(Exception e) 
{ 
    Log.e(TAG, "Failed to Notifiy the notification manager (create):\n" + e.toString()); 
} 

}

回答

1

嘗試創建一個全新的通知,並看看是否能正確地在內容視圖更新圖標。

另外,如果不爲你做,創建一個自定義內容視圖:http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomExpandedView

然後,在你的RemoteViews對象,setImageViewResource更新您的圖標,setTextViewText更新文本,並設置通知.contentView成爲您的RemoteViews對象。我已經成功地更新了狀態欄中的圖標以及擴展任務欄中的圖標/文本。

切線,我注意到你的代碼有notification.flags + = notification.FLAG_NO_CLEAR。我相信,因爲這是一個你想要的位掩碼| =而不是+ =

+0

添加通知通知=新通知(ICON,ONGOING_TEXT,System.currentTimeMillis());照顧它。 – jinanwow 2011-01-11 22:07:08