• 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、在手机上运行,点击每一个按钮即可有相应的响应。(其余功能,读者可自行润色)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    Js通用验证
    C#实现马尔科夫模型例子
    C# 生成pdf文件客户端下载
    Js跨一级域名同步cookie
    C#数据库连接池 MySql SqlServer
    关于Oracle row_number() over()的简单使用
    开发中mybatis的一些常见问题记录
    Java通过图片url地址获取图片base64位字符串的两种方式
    基于apache httpclient的常用接口调用方法
    通过jcrop和canvas的画布功能完成对图片的截图功能与视频的截图功能实现
  • 原文地址:https://www.cnblogs.com/aceview789/p/4772859.html
Copyright © 2020-2023  润新知