有谁知道如何在 Honeycomb 中的状态栏通知上施加计数器

发布于 2024-12-13 08:42:34 字数 1932 浏览 2 评论 0原文

我正在尝试使用通知类的数字字段来获取与每个通知关联的“事件数”。对于前。如果我有两封未读电子邮件,状态栏中的电子邮件图标应显示在电子邮件图标上强加的“2”。我认为这对于 froyo 来说工作得很好,但不知怎的,我无法让它为 Honeycomb 工作。这就是我的代码的样子

PendingIntent contentIntent;
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
Notification.Builder builder = new Notification.Builder(this);

builder.getNotification().number = 2; 
builder.setSmallIcon(R.drawable.phone_missedcall);
builder.setTicker("ABCD & Status : Missed Call");
notificationIntent = new Intent (this, NotificationSBActivity.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
builder.setContentIntent(contentIntent);

contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewResource(R.id.contact_image, R.drawable.ic_contact_picture);
contentView.setTextViewText(R.id.line_name, "Line 2: Cisco");
builder.setContent(contentView);

,但它没有显示在图标上强加的“2”。还有其他方法可以获取 Honeycomb 中的计数器吗? 另外,尝试过

int icon = R.drawable.phone_app;        // icon from resources
CharSequence tickerText = "Hello";              // ticker-text
long when = System.currentTimeMillis();         // notification time
Context context = getApplicationContext();      // application Context
CharSequence contentTitle = "My notification";  // message title
CharSequence contentText = "Hello World!";      // message text

notificationIntent = new Intent(this, NotificationSBActivity.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.number = 2;
mNotificationManager.notify(0, notification);

请告诉我是否有人尝试过 Honeycomb 上的通知计数器?

I am trying to use number field of Notification class to get "number of events" associated with each notification. For Ex. If I have two unread emails, email icon in the status bar should show "2" imposed on the email icon. I think this was working fine with froyo but somehow I am not able to make it work for Honeycomb. This is how my code looks like

PendingIntent contentIntent;
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
Notification.Builder builder = new Notification.Builder(this);

builder.getNotification().number = 2; 
builder.setSmallIcon(R.drawable.phone_missedcall);
builder.setTicker("ABCD & Status : Missed Call");
notificationIntent = new Intent (this, NotificationSBActivity.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
builder.setContentIntent(contentIntent);

contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewResource(R.id.contact_image, R.drawable.ic_contact_picture);
contentView.setTextViewText(R.id.line_name, "Line 2: Cisco");
builder.setContent(contentView);

But it doesn't show "2" imposed over the icon. Is there any other way to get the counter in Honeycomb ??
Also, tried

int icon = R.drawable.phone_app;        // icon from resources
CharSequence tickerText = "Hello";              // ticker-text
long when = System.currentTimeMillis();         // notification time
Context context = getApplicationContext();      // application Context
CharSequence contentTitle = "My notification";  // message title
CharSequence contentText = "Hello World!";      // message text

notificationIntent = new Intent(this, NotificationSBActivity.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.number = 2;
mNotificationManager.notify(0, notification);

Please let me know if anyone has tried notification counters on Honeycomb ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文