Delphi 10 Seattle中使用本地通知,请使用TNotificationCenter组件


本文整理自网络,侵删。

 

TNotificationCenter支持以下操作系统。
使用方法
在窗体上放置一个TNotificationCenter组件。

通知中心1

立即查看通知
使用TNotificationCenter类的PresentNotification方法。
在参数中设置要通知的信息。

procedure TForm1.Button1Click(Sender: TObject);
var
  MyNotification: TNotification;
begin
  MyNotification := NotificationCenter1.CreateNotification;
  try
    //通知唯一标识符
    MyNotification.Name := 'MyNotification';
    //通知的题目
    MyNotification.Title := '通知标题';
    //通知内容
    MyNotification.AlertBody := '通知内容';
    //立即显示通知
    NotificationCenter1.PresentNotification(MyNotification);
  finally
    MyNotification.Free;
  end;
end;
在特定日期和时间显示通知
使用TNotificationCenter类的ScheduleNotification方法。
在参数中设置要通知的信息。

procedure TForm1.Button1Click(Sender: TObject);
var
  MyNotification: TNotification;
begin
  MyNotification := NotificationCenter1.CreateNotification;
  try

    MyNotification.Name := 'MyNotification';

    MyNotification.Title := '通知标题';

    MyNotification.AlertBody := '通知内容';
    //通知发生时间
    MyNotification.FireDate := IncSecond(Now, 8);
    //将要发送的本地通知在特定的日期和时间安排
    NotificationCenter1.ScheduleNotification(MyNotification);
  finally
    MyNotification.Free;
  end;
end;
单击通知时接收事件
TNotificationCenter类具有OnReceiveLocalNotification事件。

单击通知时,将发生此事件。

下面的代码在单击通知时显示单击的通知的文本。

procedure TForm1.NotificationCenter1ReceiveLocalNotification(Sender: TObject;
  ANotification: TNotification);
begin
  Memo1.Lines.Add(ANotification.AlertBody);
end;

相关阅读 >>

Delphi xe 中的字符串生成哈希值(md5 / sha-1 / jenkins)

webbrowser点击没有id和name的按钮或链接

Delphi xe listview导出excel

Delphi 用idhttp获取utf-8编码的网页

Delphi unigui获取连接的客户端列表

Delphi 获取当前目录下的.txt文本不要带后缀扩展名

Delphi 10.3.1新的变量的声明方法

Delphi 安卓动态申请权限清单类

Delphi检测程序是否在优盘上运行

Delphi在目录中搜索文件

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...