我在我的应用程序中集成了通知,我处理了 2 种情况:使用 NotificationCompat.Builder 的 Pre Jelly bean 通知,以及使用 builder 的 Post Jelly bean 通知。这使我能够在后果冻豆版本中管理大文本和动作,并且可以工作 2 或 3 次,但奇怪的是,今天我在 JB 及以下版本中得到了相同的结果。
Pre JB 代码:
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pint = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder notif = new NotificationCompat.Builder(context)
.setContentTitle(nMessage.getTitle())
.setContentText(nMessage.getMessage())
.setTicker(nMessage.getTitle())
.setWhen(when)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setSmallIcon(R.drawable.ic_ttd_petales)
.setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
.setAutoCancel(true)
.setContentIntent(pint);
notification= notif.build();
notificationManager.notify(0, notification);
JB及以上代码:
Builder bigTextNotification = new Notification.Builder(context)
.setContentTitle(nMessage.getTitle())
.setTicker(nMessage.getTitle())
.setContentText(nMessage.getMessage())
.setWhen(when)
.setPriority(Notification.PRIORITY_HIGH)
.setSmallIcon(R.drawable.ic_ttd_petales)
.setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
.setAutoCancel(true)
.setContentIntent(pint);
if(nMessage.getHasPhone()){
Intent iCall = new Intent(Intent.ACTION_CALL,Uri.parse(nMessage.getPhone()));
PendingIntent pintCall = PendingIntent.getActivity(context, 0, iCall, Intent.FLAG_ACTIVITY_NEW_TASK);
bigTextNotification.addAction(R.drawable.ic_menu_call, context.getResources().getString(R.string.call_ttd), pintCall);
}
String[] recipients = new String[]{context.getResources().getString(R.string.default_email)};
String subject = context.getResources().getString(R.string.about_offer);
Intent iEmail = new Intent(android.content.Intent.ACTION_SEND);
iEmail.setType("text/html");
iEmail.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
iEmail.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
PendingIntent pintEmail = PendingIntent.getActivity(context, 1, iEmail, Intent.FLAG_ACTIVITY_NEW_TASK);
bigTextNotification.addAction(R.drawable.ic_menu_compose, context.getResources().getString(R.string.call_ttd), pintEmail);
Notification notif = new Notification.BigTextStyle(bigTextNotification)
.bigText(nMessage.getMessage())
.build();
notificationManager.notify(1000, notif);
你有没有遇到过这样的行为或者我错过了什么?