相关资料:

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. 92. Reverse Linked List II

    题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1- ...

  2. php cloure闭包

    Closures 它可以让您创建in-line 函数.许多语言已经开始有此功能了,也许您在不知道的情况下也使用过它. 例如: <?php $myFunction = function() { e ...

  3. [译]Atomic VS. Non-Atomic 操作

    原文链接:atomic-vs-non-atomic-operations 在网上已经写了很多关于原子操作的文章,但是通常都集中在原子的读-修改-写(RMW. read-modify-write)操作. ...

  4. Fast scroller styles

    <!-- Fast scroller styles --> <!-- Drawable to use as the fast scroll thumb. --> <att ...

  5. 【开源推荐】AllJoyn:打造全球物联网的通用开源框架

    摘要:随着智能设备的发展,物联网逐渐进入了人们的生活.据预测,未来几乎一切东西(超过500亿台设备)都可以互联.高通公司发布了开源项目AllJoyn,这是一个能够使连接设备间进行互操作的通用软件框架和 ...

  6. 如何将一个Form中的代码拆分到多个文件中

    https://social.msdn.microsoft.com/Forums/en-US/64c77755-b0c1-4447-8ac9-b5a63a681b78/partial-class-fo ...

  7. poj 2240 Arbitrage (最短路 bellman_ford)

    题目:http://poj.org/problem?id=2240 题意:给定n个货币名称,给m个货币之间的汇率,求会不会增加 和1860差不多,求有没有正环 刚开始没对,不知道为什么用 double ...

  8. NLog 传递参数

    用NLog记文件日志,一般都用{$basedir}变量,把日志记在运行的目录或者它的子目录下,遇到要写在其他目录的下,看了下Nlog找到用环境变量传参数. .net 里写 Environment.Se ...

  9. JAVA高级特性 - 注解

    注解是插入到代码中用于某种工具处理的标签.这些标签可以在源码层次上进行操作,或者可以处理编译器将其纳入到注解类文件中. 注解不会改变对程序的编译方式.Java编译器会对包含注解和不包含注解的代码生成相 ...

  10. Mongodb的范式化和反范式化

    如果是涉及到一对多的数据格式,可使用文档引用范式化数据. 在一个,User对象中,如果涉及到工作信息或者联系地址的,这些信息会频繁的进行访问,可使用嵌入式文档对数据进行反范式化.