Android实例-设置消息提醒(XE8+小米2)

相关资料:
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)的更多相关文章
- Android实例-读取设备联系人(XE8+小米2)
相关资料: http://www.colabug.com/thread-1071065-1-1.html 结果: 1.将权限打开Read contacts设置为True,不然报图一的错误. 2.搜索空 ...
- Android实例-OrientationSensor方向传感器(XE8+小米2)
相关资料: <修复 XE8 for Android 方向传感器 headingX,Y,Z 不会动的问题>:http://www.cnblogs.com/onechen/p/4497282. ...
- Android实例-TTabControl的使用(XE8+小米2)
结果: 1.如果直接改变Tab的TabIndex,那样是没有动态效果的.如果想要动态效果需要用到ChangeTabAction1; 2.ChangeTabAction1可以直接为按钮指定Action ...
- Android实例-闪光灯的控制(XE8+小米2)
unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Var ...
- Android实例-消息框(XE8+小米2)
方法一支持. 方法二与方法三都是三方单元,功能相同. 方法4与方法5报错,提示平台不支持. 第三方单元一: unit Android.JNI.Toast; // Java bridge class i ...
- Android实例-调用系统APP(XE10+小米2)
相关资料:群号383675978 实例源码: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, Sys ...
- Android实例-获取程序版本号(XE10+小米2)
相关资料: 383675978群号 实例源码: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, Sy ...
- Android实例-红外线操作(XE10.2+小米5)
相关资料: http://blog.csdn.net/qq_21752153/article/details/50244717https://developer.xamarin.com/api/typ ...
- Android 图标添加消息提醒
实现方法: 1. 在对应的布局放置TextView或者ImageView. 2. 用Canvas在原来Icon的bitmap基础上进行绘制 3. 利用开源项目ViewBadger进行添加,很方便,而且 ...
随机推荐
- Window Event 2008
https://support.microsoft.com/en-us/kb/947226
- 使用头文件climits中的符号常量获知整型数据的表数范围---gyy整理
在头文件climits(limits.h)以宏定义的方式定义了各种符号常量来表示各种整型类型表示数的范围,如int的最大最小值,long的最大最小值等. 符号常量 表示 CHAR_BIT char 的 ...
- memcached部署memcached环境及PHP扩展
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://lxsym.blog.51cto.com/1364623/876209 Memca ...
- Android 设置EditText光标位置
Android中有很多可编辑的弹出框,其中有些是让我们来修改其中的字符,这时光标位置定位在哪里呢? 刚刚解了一个bug是关于这个光标的位置的,似乎Android原生中这种情况是把光标定位到字符串的最前 ...
- WCF服务运行一段时间后客户端无法连接WCF服务的解决办法 (转)
WCF服务运行一段时间后客户端无法连接WCF服务的解决办法 (转) Windows Communication Foundation (WCF)是Microsoft为构建面向服务的应用提供的分布式通信 ...
- ActiveMQ之 TCP通讯机制
ActiveMQ支持多种通讯协议TCP/UDP等,我们选取最常用的TCP来分析ActiveMQ的通讯机制.首先我们来明确一个概念: 客户(Client):消息的生产者.消费者对ActiveMQ来说都 ...
- 使用dreamever去掉文件头部BOM(bom)信息 From 百度经验
本文来此百度经验: 地址为:http://jingyan.baidu.com/article/3f16e003c3dc172591c103e6.html OM主要处理浏览器窗口与框架,但事实上,浏览器 ...
- *gravity的取值详表
android有 android:layout_gravity 和 android:gravity,前者设置相对父控件布局,后者是设置自己内部的控件的布局. Value Description top ...
- 【HDOJ】4355 Party All the Time
好久没做过三分的题目了. /* 4355 */ #include <iostream> #include <sstream> #include <string> # ...
- C++ STL stack和queue
C++ STL中独立的序列式容器只有vector,list,deque三种,stack和queue其实就是使用容器适配器对deque进行了封装,使用了新接口. 使用标准库的栈和队列时,先包含相关的头文 ...