Android Instance-set message alert (xe8+ Xiaomi 2)

Source: Internet
Author: User

Results:

1. Two buttons to create a new message reminder, minimized is also a new message reminder.

2. The program must be minimized before clicking on the message to remind Label2 will be reflected.

Instance code:

1 UnitUnit1;2 3 Interface4 5 uses6 system.sysutils, System.types, System.uitypes, system.classes, System.variants,7 FMX. Types, FMX. Controls, FMX. Forms, FMX. Graphics, FMX. Dialogs,8 FMX. Notification, FMX. Controls.presentation, Fmx.stdctrls,9FMX. Platform;//need to introduceTen  One type ATForm1 =class(Tform) - Notificationcenter1:tnotificationcenter; - Button1:tbutton; the Button2:tbutton; - Label1:tlabel; - Label2:tlabel; - Button3:tbutton; +     procedureButton1Click (sender:tobject); -     procedureButton2click (sender:tobject); +     procedureButton3click (sender:tobject); A     procedureformcreate (sender:tobject); at     procedurenotificationcenter1receivelocalnotification (sender:tobject; - anotification:tnotification); -   Private - Flag:boolean; -     functionhandleappevent (aappevent:tapplicationevent; Acontext:tobject): Boolean; -     {Private Declarations} in    Public -     {Public Declarations} to   End; +  - var the Form1:tform1; *  $ ImplementationPanax Notoginseng {$R *.FMX} - {$R *. NMXHDPIPH.FMX ANDROID} the  + //delay Create a new message alert A procedureTform1.button1click (sender:tobject); the var + mynotification:tnotification; - begin $   //creating messages from the message center $Mynotification: =notificationcenter1.createnotification; -   Try -Mynotification.name: ='the name of the message';//set the name of the message theMynotification.alertbody: ='content of the message';//set the contents of a message -Mynotification.number: = -;//Set icon LabelWuyiMynotification.firedate: = Now + encodetime (0,0,Ten,0);//set trigger message after 10 seconds the     //submits a message to the message center and fires at a specified time - notificationcenter1.schedulenotification (mynotification); WuLabel2.Text: ="'; -   finally Aboutmynotification.disposeof;//releasing the Message interface $   End; - End; -  - //Instant New Message alert A procedureTform1.button2click (sender:tobject); + var the mynotification:tnotification; - begin $Mynotification: =notificationcenter1.createnotification;//creating messages from the message center the   Try themynotification.name:='the name of the message';//set the name of the message theMynotification.alertbody: ='content of the message';//set the contents of a message theMynotification.number: = -;//Set icon Label -Mynotification.enablesound: = True;//There's a beep . inNotificationcenter1.presentnotification (mynotification);//submit message to Message Center theLabel2.Text: ="'; the   finally Aboutmynotification.disposeof;//releasing the Message interface the   End; the End; the  + //Cancel Message Reminder - procedureTform1.button3click (sender:tobject); the beginBayiNotificationcenter1.cancelnotification ('the name of the message'); the End; the  - //The main thing is to hook up events for the program - proceduretform1.formcreate (sender:tobject); the var the Afmxapplicationeventservice:ifmxapplicationeventservice; the begin theFlag: =True; -   ifTPlatformServices.Current.SupportsPlatformService (Ifmxapplicationeventservice, IInterface ( Afmxapplicationeventservice)) Then the Afmxapplicationeventservice.setapplicationeventhandler (handleappevent) the   Else theFlag: =False;94 End; the  the //The event that will be hooked up on the program, which is a new message reminder when minimized the functiontform1.handleappevent (aappevent:tapplicationevent;98 acontext:tobject): Boolean; About var - mynotification:tnotification;101 begin102   ifFlag = False Then103 Exit;104    CaseAappevent of theTapplicationevent.aeenteredbackground://Monitor when the program is running in the background to perform the following events106     begin107       //creating messages from the message center108Mynotification: =notificationcenter1.createnotification;109       Try theMynotification.name: ='the name of the message';//set the name of the message111         //set the contents of a message theMynotification.alertbody: ='content of the message';113Mynotification.number: = -;//Set icon Label theMynotification.enablesound: =True; theNotificationcenter1.presentnotification (mynotification);//submit message to Message Center theLabel2.Text: ="';117       finally118mynotification.disposeof;//releasing the Message interface119       End; -     End;121   End;122Result: =True;123 End;124  the //This event occurs when the program is minimized, when a reminder is taken .126 proceduretform1.notificationcenter1receivelocalnotification (sender:tobject;127 anotification:tnotification); - begin129   //operation of the program after receiving the message theLabel2.Text: ='received'+ Anotification.name +'the message! ';131 End; the 133 End.

Android Instance-set message alert (xe8+ Xiaomi 2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.