gpt4 book ai didi

android - 如何创建弹出通知,例如 whatsapp for android 中使用的通知?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:12 26 4
gpt4 key购买 nike

我想创建通知,例如在 Android 设备的 WhatsApp 应用程序中使用的弹出通知。

我该怎么做?由于我是新用户,我无法上传屏幕截图

请引用此链接:http://cdn6.staztic.com/cdn/screenshot/appsdroidnotifythemeicecreamsandwich-1-1.jpg

enter image description here

屏幕截图图像并帮助我 :)

最佳答案

它们被称为“提醒”通知。 This page有一个很好的解释。

总而言之,将优先级设置为“高”(或“最大”)。

这是我的代码中的一个示例:

public static void notify(Context context, int id, int titleResId,
int textResId, PendingIntent intent) {
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String title = context.getString(titleResId);
String text = context.getString(textResId);

NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.notification)
.setContentTitle(title)
.setContentText(text)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setTicker(title)
.setContentIntent(intent);
notificationManager.notify(id, builder.build());
}

关于android - 如何创建弹出通知,例如 whatsapp for android 中使用的通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12245583/

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