2013-04-21 38 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