Android 根据设备SDK按适当的通知类型通知
我想在消息到达时通知用户,我使用了两种类型的通知(新的: 受>=4.1)支持,另一种类型适用于较旧的设备,我写了一个条件来检查设备SDK版本,并通过合适的notyfication类型通知:Android 根据设备SDK按适当的通知类型通知,android,notifications,version,Android,Notifications,Version,我想在消息到达时通知用户,我使用了两种类型的通知(新的: 受>=4.1)支持,另一种类型适用于较旧的设备,我写了一个条件来检查设备SDK版本,并通过合适的notyfication类型通知: if(Build.VERSION.SDK_INT>=4.1) { Notification notification = new Notification.Builder(context) .setContentTitle("new message from" + msg.getSt
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());
}
但在旧设备中,通知根本不起作用!
有什么帮助吗?
要点:没有错误,没有例外,只是通知不正确 在else语句中尝试以下操作:
mNotificationManager.notify(110, mBuilder.getNotification());
加几个解释性的句子怎么样?:-)我有过类似的经历,我在stackoverflow中发现了另一个问题。它说在SDK中使用了=4.1 build()。我试图找到并链接它。即使getNotification()也不起作用!(getNotification()不推荐使用,请改用build()!!