以下代码已被确认可以在运行 HONEYCOMB+ 的设备上正常工作。但是在 Samsung galaxy Y 上它没有产生任何通知。
String tickerText = userString + " Download Queued";
Notification notification = new NotificationCompat.Builder(this).setAutoCancel(true)
.setContentTitle(userString)
.setContentText("Queued")
.setSmallIcon(R.drawable.stat_sys_download_done)
.setWhen(System.currentTimeMillis())
.setTicker(tickerText)
.build();
if(DBG_ENABLE) {
LogUtils.logD(TAG_LOG, "Posting queue notification : " + 0);
}
NotificationManager notificationManager =
(NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
注意:
- 我在日志中看到“发布队列通知”。
- 我已经将 android sdk 中的 drawable
stat_sys_download_done
复制到我的项目中。
我想不出调试这个问题的方法。我不确定我是否遗漏了什么。感谢任何解决此问题的建议。
最佳答案
正如 CommonsWare 所建议的,我在 2.3 模拟器上运行该应用程序,但它崩溃了。未设置 ContentIntent 的原因。 GingerBread 需要一个 ContentIntent。所以我添加了一个虚拟的待定 Intent ,例如:
PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(this).setAutoCancel(true)
.setContentTitle(userString)
.setContentText("Queued")
.setContentIntent(pi)
.setSmallIcon(R.drawable.stat_sys_download_done)
.setWhen(System.currentTimeMillis())
.setTicker(tickerText)
.build();
关于Android : Notification not working on 2. 3.6(三星 galaxy y),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15011638/