アプリに通知を統合し、次の 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);
あなたはそのような行動に遭遇したことがありますか、それとも私は何かを見逃していますか?