gpt4 book ai didi

java - 在 Android 屏幕上显示通知

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:35:33 24 4
gpt4 key购买 nike

我正在使用此代码发送本地通知

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

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
i, PendingIntent.FLAG_ONE_SHOT);

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
.setContentTitle(title)
.setDefaults(Notification.DEFAULT_SOUND)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);

mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify((int)value, mBuilder.build());

但是如果手机屏幕滑动锁定,它们会显示在状态栏上。我想在屏幕顶部显示推送通知,如 whatsapp、facebook、短信等。

我怎样才能做到这一点?

最佳答案

你可以这样做:

通过添加以下行:

setPriority(Notification.PRIORITY_MAX)

完整代码:

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

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
i, PendingIntent.FLAG_ONE_SHOT);

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
.setContentTitle(title)
.setDefaults(Notification.DEFAULT_SOUND)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg)
.setPriority(Notification.PRIORITY_MAX);

mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify((int)value, mBuilder.build());

希望对您有所帮助。

关于java - 在 Android 屏幕上显示通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35994055/

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