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进行添加,很方便,而且 ...
随机推荐
- 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)
Rotating Scoreboard Description This year, ACM/ICPC World finals will be held in a hall in form of a ...
- [itint5]完全二叉树节点个数的统计
http://www.itint5.com/oj/#4 这题是利用完全二叉树的性质计算节点数目.那么是通过比较左右子树的最左结点的高度来看那边是满的,然后递归计算. //使用getLeftChildN ...
- seek和tell的用法--获取文件内容大小(字节)
/*获取文件中存取的数据内容的大小(字节数) ellg() 和 tellp() 这两个成员函数不用传入参数,返回pos_type 类型的值(根据ANSI-C++ 标准) ,就是一个整数,代表当前get ...
- 编程实现Windows关机、重启、注销
要想编程使Windows关机.重启或者注销,可以使用ExWindowsEx这个API函数,该函数只有两个参数,第一个表示关机动作的标志,也就是你要让该函数关机呢,还是重启,还是注销等.可以使用EWX_ ...
- POJ2533——Longest Ordered Subsequence(简单的DP)
Longest Ordered Subsequence DescriptionA numeric sequence of ai is ordered if a1 < a2 < ... &l ...
- Android 自绘TextView解决提前换行问题,支持图文混排
先看下效果图: 上面是MTextView,下面是默认的TextView. 一.原因 用最简单的全英文句子为例,如果有一个很长的单词,这一行剩余的空间显示不下了,那么规则就是不打断单词,而是把整个单词丢 ...
- NuGet相关的文章
NuGet学习笔记(1)——初识NuGet及快速安装使用http://www.cnblogs.com/zhwl/p/3377510.html NuGet学习笔记(2) 使用图形化界面打包自己的类库ht ...
- [ffmpeg 扩展第三方库编译系列] 关于libvpx mingw32编译问题
在编译libvpx的时候遇到挺多的问题, 1.[STRIP] libvpx.a < libvpx_g.a strip: Bad file number 这个错误也是比较难搞的,一开始以为只是 ...
- SQLServer与Oracle的数据同步(触发器trigger)
说到同步,其实是靠"作业"定时调度存储过程来操作数据,增,删,改,全在里面,结合触发器,游标来实现,关于作业调度,使用了5秒运行一次来实行"秒级作业",这样基本 ...
- 配置oschina for pc 开发环境
oschina for pc 是一款用python + pyqt + html + css +js开发的桌面程序,感觉十分强大.python开发快捷, 网页技术绚丽,正是桌面程序需要的. 感谢铂金小鸟 ...