2013-04-21 58 views
1

這是我的代碼:如何獲得通知,通知沒有持續

Notification n = new Notification(); 
n.icon = R.drawable.ic_launcher; 
n.tickerText="test"; 
n.defaults |= Notification.DEFAULT_ALL; 

Intent dummyIntent = new Intent(); 
dummyIntent.setAction("dummy"); 
PendingIntent pi = PendingIntent.getBroadcast(c, 0, dummyIntent, 0); 
n.setLatestEventInfo(c, "test","test", pi); 

NotificationManager nm = (NotificationManager)c.getSystemService(Context.NOTIFICATION_SERVICE); 
    nm.notify(1, n); 

我想把這個作爲通知不是正在進行中。 但是這個通知被標示爲onGoing? 爲什麼?

回答

2

,您可以建立在這樣的通知,這是一個用於創建聲明和讓你自定義它們比舊的更好,因爲你可以看到herehere新方法。

NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
notificationBuilder = new NotificationCompat.Builder(mContext); 
notificationBuilder.setContentTitle("Title") 
          .setContentText("Text") 
          .setSmallIcon(R.drawable.icon) 
          .setContentIntent(contentIntent) 
          .setOngoing(false) 
          .setTicker("Ticker Text"); 

隨着setOngoing(),你可以將其設置爲truefalse