【发布时间】:2011-08-12 13:26:23
【问题描述】:
我希望能够触发通知以提醒用户计时器已完成,但是我不希望在您单击通知时有意图。
我已经尝试为意图传递 null
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
int icon = R.drawable.icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
notification.setLatestEventInfo(context, contentTitle, contentText, null);
mNotificationManager.notify(HELLO_ID, notification);
【问题讨论】:
-
只是一个关于这个 null 方法的警告——我也在寻找这个答案。在我的 HTC Desire 上,这会导致设备重启!很糟糕,因为通知是在启动时创建的 - 所以我进入了启动-重启-启动循环......
-
有趣的是,null 在 4.0 模拟器上也能正常工作。它会在我的 Galaxy S2 (2.3) 上导致 FC。
-
它真的很有用。非常感谢
标签: android notifications android-intent notificationmanager