回复
HarmonyOS开发-通知开发体验
鸿蒙时代
发布于 2022-3-15 14:39
浏览
1收藏
HarmonyOS提供了通知功能,即在一个应用的UI界面之外显示的消息,主要用来提醒用户有来自该应用中的信息。当应用向系统发出通知时,它将先以图标的形式显示在通知栏中,用户可以下拉通知栏查看通知的详细信息。
效果如下:
代码如下:
NotificationSlot slot = new NotificationSlot("slot_001", "slot_default", NotificationSlot.LEVEL_MIN); // 创建notificationSlot对象
slot.setDescription("NotificationSlotDescription");
slot.setEnableVibration(true); // 设置振动提醒
slot.setEnableLight(true); // 设置开启呼吸灯提醒
slot.setLedLightColor(Color.RED.getValue());// 设置呼吸灯的提醒颜色
try {
NotificationHelper.addNotificationSlot(slot);
} catch (RemoteException ex) {
HiLog.error((HiLogLabel) LABEL, "Exception occurred during addNotificationSlot invocation.");
}
int notificationId = 1;
NotificationRequest request = new NotificationRequest(notificationId);
request.setSlotId(slot.getId());
String title = "消息";
String text = "哈哈哈哈哈哈哈哈";
NotificationRequest.NotificationNormalContent content = new NotificationRequest.NotificationNormalContent();
content.setTitle(title)
.setText(text);
NotificationRequest.NotificationContent notificationContent = new NotificationRequest.NotificationContent(content);
request.setContent(notificationContent); // 设置通知的内容
try {
NotificationHelper.publishNotification(request);
} catch (RemoteException ex) {
HiLog.error((HiLogLabel) LABEL, "Exception occurred during publishNotification invocation.");
}
}
分类
标签
HarmonyOS开发-通知开发体验.docx 35.07K 16次下载
NotificationSlot通知开发体验.rar 361.71K 21次下载
赞
2
收藏 1
回复
相关推荐