gpt4 book ai didi

android - 当应用程序处于前台时,如何在前面而不是在带有通知图标的状态栏上显示通知?

转载 作者:行者123 更新时间:2023-11-29 17:00:13 25 4
gpt4 key购买 nike

我的代码如下所示:

private void sendNotification(String messageBody) {
Intent intent = new Intent(this, OrderHistory.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(Consts.NOTIFICATION_ORDER_ID, notificationMap.get(Consts.NOTIFICATION_ORDER_ID));
intent.putExtra(Consts.NOTIFICATION_ORDER_STATUS,
notificationMap.get(Consts.NOTIFICATION_ORDER_STATUS));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("QuFlip")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent);

NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0, notificationBuilder.build());
}

现在,每当通知到来时,它都会在状态栏中默认显示 android 应用程序图标。但我想做的是,我想显示适当的通知,就像应用程序未运行时一样。

最佳答案

试试 setLargeIcon(R.mipmap.ic_launcher)。如果没有帮助,请尝试添加:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
}

关于android - 当应用程序处于前台时,如何在前面而不是在带有通知图标的状态栏上显示通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43351580/

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