我想在消息到达时通知用户,我使用了两种类型的通知,(新增: 由> = 4.1支持,而另一种类型用于旧设备,我写了一个条件来检查设备SDK版本并通过合适的notyfication类型通知:
if(Build.VERSION.SDK_INT>=4.1) {
Notification notification = new Notification.Builder(context)
.setContentTitle("new message from" + msg.getString(ConstantsGCM.NAME_CLM))
.setContentText(msg.getString(ConstantsGCM.BODYCLM))
.setSmallIcon(icon)
.setLargeIcon(bm)
.setAutoCancel(true)
.setWhen(when).setVibrate(viber)
.setContentIntent(contentIntent)
.build();
if (EntryActivity.useSound.equals("yes"))
if (!ring.equals(""))
notification.sound = (Uri.parse(ring));
else notification.defaults = Notification.DEFAULT_SOUND;
mNotificationManager.notify(110, notification);
}else { //old type..
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.newlogo)
.setContentTitle("new message from" + msg.getString(ConstantsGCM.NAME_CLM))
.setContentText(msg.getString(ConstantsGCM.BODYCLM))
.setContentIntent(contentIntent)
.setLargeIcon(bm)
.setAutoCancel(true)
.setWhen(when);
if (EntryActivity.useSound.equals("yes"))
if (!ring.equals(""))
mBuilder.setSound(Uri.parse(ring));
else mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mNotificationManager.notify(110, mBuilder.build());
}
但在较旧的设备中,通知根本不起作用! 有帮助吗? 要点:没有错误,没有例外,只是通知没有发生!
答案 0 :(得分:0)
在你的else语句中试试这个:
mNotificationManager.notify(110, mBuilder.getNotification());