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?为什么?

4

1 回答 1

2

您可以通过这种方式构建通知,这是创建通知的新方法,让您可以比旧方法更好地自定义它们,正如您在此处此处看到的那样。

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

于 2013-04-21T22:28:24.427 回答