相关资料:

1.官网实例:http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Using_the_Notification_Center_(iOS_and_Android)

结果:

1.二个按钮可以新建消息提醒,最小化也是新建消息提醒。

2.程序必须最小化后才能点击消息提醒Label2才会有反映。

实例代码:

 unit Unit1;

 interface

 uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Notification, FMX.Controls.Presentation, FMX.StdCtrls,
FMX.Platform;//需要引入 type
TForm1 = class(TForm)
NotificationCenter1: TNotificationCenter;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure NotificationCenter1ReceiveLocalNotification(Sender: TObject;
ANotification: TNotification);
private
flag: Boolean;
function HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation
{$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID} //延时新建一个消息提醒
procedure TForm1.Button1Click(Sender: TObject);
var
MyNotification: TNotification;
begin
//通过消息中心创建消息
MyNotification := NotificationCenter1.CreateNotification;
try
MyNotification.Name := '消息的名称'; //设置消息的名称
MyNotification.AlertBody := '消息的内容'; //设置消息的内容
MyNotification.Number := ;//设置图标标号
MyNotification.FireDate := Now + EncodeTime(,, , ); //设置 10 秒后触发消息
//将消息提交消息中心,并于指定时间触发
NotificationCenter1.ScheduleNotification(MyNotification);
Label2.Text := '';
finally
MyNotification.DisposeOf; //释放消息接口
end;
end; //即时新建消息提醒
procedure TForm1.Button2Click(Sender: TObject);
var
MyNotification: TNotification;
begin
MyNotification :=NotificationCenter1.CreateNotification; //通过消息中心创建消息
try
MyNotification.Name:= '消息的名称'; //设置消息的名称
MyNotification.AlertBody := '消息的内容'; //设置消息的内容
MyNotification.Number := ;//设置图标标号
MyNotification.EnableSound := True;//有提示音
NotificationCenter1.PresentNotification(MyNotification); //将消息提交消息中心
Label2.Text := '';
finally
MyNotification.DisposeOf; //释放消息接口
end;
end; //取消消息提醒
procedure TForm1.Button3Click(Sender: TObject);
begin
NotificationCenter1.CancelNotification('消息的名称');
end; //主要是为程序挂接事件
procedure TForm1.FormCreate(Sender: TObject);
var
aFMXApplicationEventService: IFMXApplicationEventService;
begin
flag := True;
if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(aFMXApplicationEventService)) then
aFMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent)
else
flag := False;
end; //将要挂接在程序上的事件,此事件是最小化时新建一个消息提醒
function TForm1.HandleAppEvent(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
var
MyNotification: TNotification;
begin
if flag = False then
Exit;
case AAppEvent of
TApplicationEvent.aeEnteredBackground://监测,当程序后台运行时执行以下事件
begin
//通过消息中心创建消息
MyNotification := NotificationCenter1.CreateNotification;
try
MyNotification.Name :='消息的名称'; //设置消息的名称
//设置消息的内容
MyNotification.AlertBody := '消息的内容';
MyNotification.Number := ; //设置图标标号
MyNotification.EnableSound := True;
NotificationCenter1.PresentNotification(MyNotification); //将消息提交消息中心
Label2.Text := '';
finally
MyNotification.DisposeOf; //释放消息接口
end;
end;
end;
Result := True;
end; //程序最小化后,点消提醒时,发生此事件
procedure TForm1.NotificationCenter1ReceiveLocalNotification(Sender: TObject;
ANotification: TNotification);
begin
//收到消息后程序的操作
Label2.Text := '收到' + ANotification.Name + '的消息!';
end; end.

Android实例-设置消息提醒(XE8+小米2)的更多相关文章

  1. Android实例-读取设备联系人(XE8+小米2)

    相关资料: http://www.colabug.com/thread-1071065-1-1.html 结果: 1.将权限打开Read contacts设置为True,不然报图一的错误. 2.搜索空 ...

  2. Android实例-OrientationSensor方向传感器(XE8+小米2)

    相关资料: <修复 XE8 for Android 方向传感器 headingX,Y,Z 不会动的问题>:http://www.cnblogs.com/onechen/p/4497282. ...

  3. Android实例-TTabControl的使用(XE8+小米2)

    结果:  1.如果直接改变Tab的TabIndex,那样是没有动态效果的.如果想要动态效果需要用到ChangeTabAction1; 2.ChangeTabAction1可以直接为按钮指定Action ...

  4. Android实例-闪光灯的控制(XE8+小米2)

    unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Var ...

  5. Android实例-消息框(XE8+小米2)

    方法一支持. 方法二与方法三都是三方单元,功能相同. 方法4与方法5报错,提示平台不支持. 第三方单元一: unit Android.JNI.Toast; // Java bridge class i ...

  6. Android实例-调用系统APP(XE10+小米2)

    相关资料:群号383675978 实例源码: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, Sys ...

  7. Android实例-获取程序版本号(XE10+小米2)

    相关资料: 383675978群号 实例源码: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, Sy ...

  8. Android实例-红外线操作(XE10.2+小米5)

    相关资料: http://blog.csdn.net/qq_21752153/article/details/50244717https://developer.xamarin.com/api/typ ...

  9. Android 图标添加消息提醒

    实现方法: 1. 在对应的布局放置TextView或者ImageView. 2. 用Canvas在原来Icon的bitmap基础上进行绘制 3. 利用开源项目ViewBadger进行添加,很方便,而且 ...

随机推荐

  1. iOS 图片背景模糊效果

    iOS 图片背景模糊效果 1.使用CoreImage中的模糊滤镜 原始效果图如下: CoreImage的实现: - (void)viewDidLoad { [super viewDidLoad]; / ...

  2. SPRING IN ACTION 第4版笔记-第九章Securing web applications-005-Applying LDAP-backed authentication

    一. 1.This method is the  LDAP analog to  jdbcAuthentication() @Override protected void configure(Aut ...

  3. ANDROID_MARS学习笔记_S01_004dpi、dp(dip)及计算

    一.dpi.dp介绍 sp会随着用户在手机中设置字体大小而改变,而dp不会 二.1.dpsp_layout.xml <?xml version="1.0" encoding= ...

  4. Flash Builder 4.6 基本设置

    Flash Builder 4.6 字体修改 打开Flash Builder4.6 -> 窗口 -> 首选项 -> 左边目录选择常规 -> 外观 -> 颜色和字体 -&g ...

  5. 【HDOJ】4347 The Closest M Points

    居然是KD解. /* 4347 */ #include <iostream> #include <sstream> #include <string> #inclu ...

  6. js控制元素的显示与隐藏

    <body class="easyui-layout"> <div id = "centerId" data-options="re ...

  7. poj1180

    斜率优化dp 据说这题朴素的O(n2)dp也可以A 没试过 朴素的dp不难想:f[i]=min(f[j]+sumtime[i]*sumcost[j+1,i]+c*sumcost[j+1,n]) 稍微解 ...

  8. 使用HQL查询

    HQL是Hibernate Query Language的缩写,语法很想SQL,但是HQL是一种面向对象的查询语言.SQL的操作对象是数据列.表等数据库对象,而HQL操作的是类.实例.属性. HQL查 ...

  9. Web打印控件smsx.cab使用说明

    在项目开发中,经常会用到页面打印的功能,在ASP.NET环境下推荐一款web打印控件smsx.cab.    使用方法:一般会先定义一个用于打印的母版页(Print.Master),在母版页上做好布局 ...

  10. [2015编程之美] 资格赛C

    #1150 : 基站选址 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 需要在一个N × M的网格中建立一个通讯基站,通讯基站仅必须建立在格点上. 网格中有A个用户,每个 ...