RAD Studio XE8实现手机提示和通知

1、打开XE8,新建Mutli-Device  Form-C++ Builder工程,在Form中加入组件NotificationCenter;

注意:系统通知只能在手机上运行,所以平台要更换为andriod或者iOS等

2、在.cpp中加入头文件

#include<FMX.Platform.hpp>

#include<System.IOUtils.hpp>

#include<FMX.Notification.hpp>

3、在.h文件中加入GetSoundName()方法的声明:UnicodeString __fastcall GetSoundName();

4、加入各个按钮,分别写入代码:

// ----------------------- 发送通知------------------

void __fastcall TForm1::Button1Click(TObject *Sender)

{

TNotification *myNotification=NotificationCenter1->CreateNotification();

__try{

myNotification->Number=3;

myNotification->AlertBody=L"发送通知";

//myNotification->FireDate=Now()+EncodeTime(0,0,10,0);

NotificationCenter1->ScheduleNotification(myNotification);

}__finally {        //因为finally不在标准中,所以要加下划线

myNotification->DisposeOf();

}

}

//------------------ 稍后通知,如10秒后-------------

void __fastcall TForm1::Button2Click(TObject *Sender)

{

if(NotificationCenter1->Supported()){

TNotification *myNotification=NotificationCenter1->CreateNotification();

__try{

myNotification->Number=3;

myNotification->AlertBody=L"10秒后再提醒";

myNotification->FireDate=Now()+EncodeTime(0,0,10,0);

NotificationCenter1->ScheduleNotification(myNotification);

}__finally {

myNotification->DisposeOf();

}

}

}

//--------------- 重复通知-------------------

void __fastcall TForm1::Button3Click(TObject *Sender)

{

if(NotificationCenter1->Supported()){

TNotification *myNotification=NotificationCenter1->CreateNotification();

__try{

myNotification->Name="myNotification";

myNotification->AlertBody=L"每分钟重复通知";

myNotification->FireDate= Now()+EncodeTime(0,0,10,0);

myNotification->RepeatInterval=TRepeatInterval::Minute;

NotificationCenter1->ScheduleNotification(myNotification);

} __finally{

myNotification->DisposeOf();

}

}

}

//--------------------- 取消通知-----------------

void __fastcall TForm1::Button4Click(TObject *Sender)

{

NotificationCenter1->CancelNotification("myNotification");

}

//--------------------------- 有铃声的通知(注意:手机设置功能里是否有关闭通知铃声)--------------------

void __fastcall TForm1::Button5Click(TObject *Sender)

{

if(NotificationCenter1->Supported()){

TNotification *myNotification=NotificationCenter1->CreateNotification();

__try{

myNotification->Name="myNotification";

myNotification->AlertBody=L"这是我的通知,立即发送";

myNotification->EnableSound=true;

myNotification->SoundName=GetSoundName();

NotificationCenter1->PresentNotification(myNotification);

} __finally{

myNotification->DisposeOf();

}

}

}

//------------------------- GetSoundName()方法----------------------

UnicodeString __fastcall TForm1::GetSoundName(){

UnicodeString result=

System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetSharedDocumentsPath(),"soundsample.mp3");

return result;

}

5、点击NotificationCenter组件,双击Events里的OnReceiveLocalNotification事件,写入代码:

//--------------------------- 收到通知,提示“已阅读”--------------------

void __fastcall TForm1::NotificationCenter1ReceiveLocalNotification(TObject *Sender,

TNotification *ANotification)

{

ShowMessage("已阅读");

}

6、在手机上运行,点击每一个按钮即可有相应的响应。(其余功能,读者可自行润色)

时间: 2024-08-29 08:00:12

RAD Studio XE8实现手机提示和通知的相关文章

RAD Studio XE8 用控件实现数据库的增删改

一.设置数据库 解压缩:mysql-workbench-community-6.3.4-win32-noinstall.mysql-5.6.25-win32 打开mysql-5.6.25-win32到bin,打开mysqld.exe,执行后自动退出后,打开mysql-workbench-community-6.3.4-win32-noinstall中的MySQLWorkbench.exe,即可打开数据库,自定义新建连接即可,这个较为方便,解压后直接使用,无需再去配置环境. 数据的字符集的统一:u

RAD Studio XE8跨平台实现APP中的录音、录像功能

一.打开RAD Studio XE8,新建工程,加入组件MediaPlayer.CameraComponent和一些按钮,从上到下一次为Button1.2.3.4.5.6.7.8: 二.在头文件.h中加入:#include <FMX.Media.hpp>,以及 __published: void __fastcall GetImage(); private: TAudioCaptureDevice *Microphone; //声明麦克风 String FileName; 三.在各个按钮中写入

RAD Studio XE8 技术研讨会讲义与范例程序下载

?? 感谢各位程序猿亲临现场參加我们的公布会,现奉上会议当天的讲义与范例程序供大家參考: 2015/5/25~27北京.深圳 『RAD Studio XE8技术研讨会』 下载讲义:http://pan.baidu.com/s/1o6Dp7iM 下载范例程序:http://pan.baidu.com/s/1i3oxmex 好消息! 为加速用户熟悉 Delphi及C++Builder产品,我们即将推出Delphi XE8及 C++Builder XE8中文手冊,如需购买客户可传送电邮至[email 

Delphi XE8,C++ Builder XE8,RAD Studio XE8 官方 ISO 文件下载,附激活工具

用迅雷下载的文件总是有问题.还是用浏览器的内置下载吧! ! . Update 1版请參见: http://blog.csdn.net/maxwoods/article/details/46822369 RAD Studio XE8 v22.0.19027.8951 官方ISO下载(6.72G):http://altd.embarcadero.com/download/radstudio/xe8/delphicbuilder_xe8_win.iso 安装序列号: QNDH-SNDR63-GQULQ

RAD Studio 10 安装失败 提示错误 License status check failure解决办法

最近在安装RAD Studio 10.1 Berlin 时,运行光盘中的setup.exe,在第一页勾选 lincense agreement后下一步,提示如下错误,无法进行安装. License status check failure License status check failure (Error code: 255). Please try again later, or contact support. 通过一番搜索和尝试得到以下解决办法: 问题原因: 由于电脑中已经安装过其他版

RAD Studio XE8 在APP里实现手机的拨号功能

1.新建Muilti Device C++ Builder工程,在 .h 中加入2个头文件: #include <FMX.PlatForm.hpp> #include<FMX.PhoneDialer.hpp> 2.加入private声明变量:_di_IFMXPhoneDialerService phoneDialerService;(无需加*,但类型是指针) __published声明方法: void __fastcall MyOnCallStateChanged (const U

[免费活动通知]RAD Studio XE8 技术研讨会(上海、成都)

 活动类型:免费研讨会 报名链接: http://forms.embarcadero.com/AP15Q3CNRADStudioDeepDiveSeminar 上海 2015 年 8 月 13 日 13:30pm~17:00pm 上海君丽大酒店 中国上海市遵义路 448 号 3 楼 ((乘坐地铁二号线至娄山关路站, 1号出口往外步行至天山路与遵义路交汇点, 左转进入遵义路后向前走200米)3 楼 君丽宴会厅 成都 2015 年 8 月 15 日 13:30pm~17:00pm 成都富力丽思卡

[免费活动通知]RAD Studio XE8 技术研讨会(北京、深圳)

 活动类型:免费研讨会 报名链接: http://forms.embarcadero.com/AP15Q2CNDeveloperDirectLIVE 北京 5 月 25 日 13:30pm~17:00pm 北京昆泰嘉华酒店 北京市朝阳区朝外大街乙12号 (距离朝阳门地铁400米) 3层 6 号会议室 http://www.kuntairoyalhotel.com/about_hotel.html 深圳 5 月 27 日 (三) 13:30pm~17:00pm 深圳博林诺富特酒店 深圳市福田区

RAD Studio 2010~XE8 官方 ISO 下载地址 (2015-03-28更新)

http://bbs.csdn.net/topics/390816856 RAD Studio XE8 目前最新版 v22.0.19027.8951 官方 ISO 文件下载(6.72GB):http://altd.embarcadero.com/download/radstudio/xe8/delphicbuilder_xe8_win.iso RAD Studio XE7 最终版 (with Update 1) v21.0.17707.5020 官方 ISO 文件下载(5.26GB):http: