zoukankan      html  css  js  c++  java
  • 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、在手机上运行,点击每一个按钮即可有相应的响应。(其余功能,读者可自行润色)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    语法上的小trick
    [算法模版]斜率优化
    CF886E Maximum Element
    【hdu 1576】A/B(数论--拓展欧几里德 求逆元 模版题)
    【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)
    【poj 2478】Farey Sequence(数论--欧拉函数 找规律求前缀和)
    【poj 1284】Primitive Roots(数论--欧拉函数 求原根个数){费马小定理、欧拉定理}
    【poj 2407】Relatives(数论--欧拉函数 模版题)
    【bzoj 2038】 [2009国家集训队]小Z的袜子(算法效率--莫队分块算法 模版题)
    【uva 1312】Cricket Field(算法效率--技巧枚举)
  • 原文地址:https://www.cnblogs.com/aceview789/p/4772859.html
Copyright © 2011-2022 走看看