zoukankan      html  css  js  c++  java
  • Delphi XE5 for Android (十一)

    以下内容是根据Delphi的帮助文件进行试验的,主要测试Android下的消息提醒。

    首先建立一个空白的Android工程,然后在窗体中加入一个TNotificationCenter控件,如下图:

    image

    再在uses中引用文件,如下:

    uses
      FMX.Platform;
    窗体上控件放置如下图:
    image
     
    发送消息的代码如下:
    procedure TForm2.Button2Click(Sender: TObject);
    var
      MyNotification: TNotification;
    begin
      //通过消息中心创建消息
      MyNotification := NotificationCenter1.CreateNotification;
      try
        //设置消息的名称
        MyNotification.Name := 'Schedule Notification';
        //设置消息的内容
        MyNotification.AlertBody := 'Schedule Notification:' + edtSchedule.Text;
        //设置图标标号
        MyNotification.Number := 18;
    
        //设置10秒后触发消息
        MyNotification.FireDate := Now + EncodeTime(0, 0, 10, 0);
        //将消息提交消息中心,并于指定时间触发,直接发送用PresentNotification
        NotificationCenter1.ScheduleNotification(MyNotification);
      finally
        //释放消息接口
        MyNotification.DisposeOf;
      end;
    end;

    运行后,点击Schedule按钮10秒后看到消息提示,如下图:

    image

    当用户点击消息时,触发onReceiveLocalNotification事件,通过ANotification参数了解到客户点击的是哪条消息并作出处理。代码如下:

    procedure TForm2.NotificationCenter1ReceiveLocalNotification(Sender: TObject;
      ANotification: TNotification);
    begin
      //收到用户对消息的操作
      Label1.Text := '收到' + ANotification.Name + '的消息';
    end;

    执行结果如下图:

    image

    注意:不要按照Help中的例子在onReceiveLocalNotification事件使用ShowMessage,在Android下不仅不能显示,由于弹出的对话框被覆盖,会导致整个程序假死。

  • 相关阅读:
    hdu 5446 Unknown Treasure lucas和CRT
    Hdu 5444 Elven Postman dfs
    hdu 5443 The Water Problem 线段树
    hdu 5442 Favorite Donut 后缀数组
    hdu 5441 Travel 离线带权并查集
    hdu 5438 Ponds 拓扑排序
    hdu 5437 Alisha’s Party 优先队列
    HDU 5433 Xiao Ming climbing dp
    hdu 5432 Pyramid Split 二分
    Codeforces Round #319 (Div. 1) B. Invariance of Tree 构造
  • 原文地址:https://www.cnblogs.com/china1/p/3410921.html
Copyright © 2011-2022 走看看