The use of Android drip pendingintent

Source: Internet
Author: User

A concept pendingintent is a intent that can be executed under certain conditions, and its advantage over intent is that it carries a context object so that he does not have to rely on an activity to exist.
The main difference between it and intent is that the execution of intent is immediate, and Pendingintent's execution is not immediate. the action performed by the pendingintent is essentially the intent operation of the parameter, but using the The purpose of the pendingintent is that the execution of the intent operation that it contains needs to meet certain conditions.
Two substancependingintentcan be seen as theIntentthe packaging. pendingintentThe main possession of the information is that it is packagedIntentand the currentApplicationof theContext. Just becausependingintentis saved with the currentApplicationof theContext, giving it a way to carry out a program.Intentthe ability to do so, even if the currentApplicationno longer exists, it can be passed through existence.pendingintentin theContextstill executeIntent.
three common usage scenarios and codes1. Timer Alarm
Pendingintent pi1 = Pendingintent.getbroadcast (context,autotimeringbroadcast1.class,1);//Create intent Alarmmanager AM = ( Alarmmanager) Context.getsystemservice (context.alarm_service);         Am.setrepeating (alarmmanager.rtc_wakeup,time,1000*60*60*24, pi),//time is the target time millisecond value, repeated execution can

2. Notification Click to open the interface
Notificationmanager Mnotificationmanager = (notificationmanager) getsystemservice (context.notification_service) int icon = Android. R.drawable.stat_notify_chat;long when = System.currenttimemillis ();//notification occurs at the current time of the system//create a new notification, specifying its icon and caption notification notification = new notification (icon, null, when);//The first parameter is an icon, the second parameter is a short tip title, and the third is the notification time Notification.defaults = notification.default_sound;//make default sound notification.flags |= notification.flag_auto_cancel;//automatically clear notifications after clicking Notifications Intent Openintent = new Intent (this, otheractivity.class); Pendingintent contentintent = pendingintent.getactivity (this, 0, openintent, 0);// When the message is clicked, the Openintent intent Notification.setlatesteventinfo (this, "title", "I am Content", contentintent) is sent to the system;//The thing to do after clicking Contentintent Task mnotificationmanager.notify (0, notification);//The first parameter is a custom notification unique identifier, issue this notification!
3. Get receipts after sending SMS

Smsmanager the way to send SMS:

Sendtextmessage (destinationaddress, scaddress, text, sentintent, deliveryintent);

First parameter:destinationaddress Each other's mobile phone number

Second parameter:scaddress SMS Center number is generally set to empty

Third parameter:text text message content

The fourth parameter:sentintent Determine whether the text message is sent successfully, if you do not have a SIM card, or network interruption, you can use this itent to judge. Note the emphasis is on whether the "send" action was successful. So as for whether or not the other party received

Fifth parameter:deliveryintent When a text message is sent to the recipient, the deliveryintentis received. The result of "send" is emphasized.

That is, the " message sent successfully " and "The other received this message " will activate sentintent and deliveryintent these two Intent. This is also equivalent to delaying the execution of the Intent

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: 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.