2015-04-03 77 views
0

我想創建一個通知,用戶無法通過向左或向右拖動來關閉它。 用戶必須點擊但願關閉通知Android通知點擊後立即清除

我的代碼是:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com")); 
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); 
Notification n = new Notification.Builder(getApplicationContext()) 
        .setContentTitle("title") 
        .setContentText("text") 
        .setSmallIcon(R.drawable.ic_tt) 
        .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_tt)) 
        .setContentIntent(pIntent) 
        .setDefaults(Notification.DEFAULT_SOUND) 
        .setOngoing(true).build(); 
        n.flags |= Notification.FLAG_ONGOING_EVENT; 

    NotificationManager notificationManager =(NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    notificationManager.notify(0, n); 

但dosnot工作 什麼想法?

+0

根本不顯示通知,或者只顯示爲正常通知? – s3lph 2015-04-03 10:35:49

+0

@the_Seppi通知顯示,但不能關閉。 – 2015-04-03 10:38:21

+0

顯示爲正在進行還是正常? – s3lph 2015-04-03 10:39:30

回答

1

您需要使用這兩種功能保留通知,

nBuilder.setOngoing(true); 
nBuilder.setAutoCancel(true); 

它只能在用戶點擊它被取消。 在此Managing Notifications中查找setAutoCancel。 希望這有助於!