2014-12-03 55 views
0

我有下面的代碼在Android狀態欄上創建一個圖標。如何修復Android狀態欄中的圖標

Context context = getApplicationContext(); 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 
    .setSmallIcon(R.drawable.ic_launcher) 
    .setContentTitle(getString(R.string.app_name)) 
    .setContentText("Live Tracking"); 

Intent intent = new Intent(context, MainActivity.class); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
PendingIntent pIntent = PendingIntent.getActivity(context, mID , intent, 0); 
builder.setContentIntent(pIntent); 
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

Notification notif = builder.build(); 
mNotificationManager.notify(mID, notif); 

當用戶按下「清除每個通知」按鈕時,是否有辦法防止圖標被刪除?

非常感謝您的幫助。 問候, 文森特。

回答

1

setOngoing(true)添加到您的通知構建器。這仍然堅持通知,所以你必須確保你自己刪除它

+0

非常感謝! – Vincent 2014-12-03 16:05:41