gpt4 book ai didi

Android Jelly Bean 奇怪的通知行为

转载 作者:行者123 更新时间:2023-11-30 03:46:56 27 4
gpt4 key购买 nike

我在我的应用程序中集成了通知,我已经处理了 2 个案例:使用 NotificationCompat.Builder 的 Pre Jelly bean 通知,以及使用生成器发布 Jelly bean 通知。这使我能够在 post jelly bean 版本中管理大文本和操作,并工作了 2 或 3 次,但奇怪的是,今天我在 JB 及以下版本中得到了相同的结果。

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);

你有没有遇到过这样的行为,或者我错过了什么?

最佳答案

我有过类似的经历:我会发送通知,它会显示内容文本而不是大文本。然后,当我拔下 USB 时,它会显示扩展的大文本。

现在请注意,当您插入 USB 时,您会收到一条持续通知:“已作为媒体设备连接”。看看您是否在其他一些正在进行的通知中遇到相同的行为,例如“正在使用 GPS 进行搜索”。我愿意。 (我的测试设备是三星 Galaxy Rush,它的垂直空间非常有限。)

所以虽然 Android Notifications documentation说只有顶部通知显示为已展开,看起来还有另一条规则:

如果通知列表空间不足,它甚至会折叠顶部通知。

您可以通过双指或单指拖动展开折叠的通知,具体取决于操作系统版本。

关于Android Jelly Bean 奇怪的通知行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14851939/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com