Learn about android-Notification, android

Source: Internet
Author: User

Learn about android-Notification, android

Notification can be understood as the meaning of the Notification and will appear in the Notification bar. For example, a text message is sent.

Follow these steps to use Notification:

1. Create the icationicationmanager object

2. Set attributes for Notification

3. Use icationy provided by icationicationmanager to send notifications

 

Instance: send a notification

1/** 2 * Create notify 3 */4 private void createnoworkflow () {5 // create icationicationmanager object 6 icationicationmanager manager = (icationicationmanager) getSystemService (icationication_service ); 7 // create policycation object 8 Notification every Y = new Notification (); 9 Every y. icon = R. drawable. icon_reply; // set the icon to 10 y. when = System. currentTimeMillis (); // The time when the notification is sent. 11 notify. tickerText = "hi, I'm Coming"; // The prompt text is 12 y. flags = Notification. FLAG_AUTO_CANCEL; // automatically cancels 13 Intent intent = new Intent (this, NextActivity. class); 14 PendingIntent pIntent = PendingIntent. getActivity (this, 0, intent, 15 PendingIntent. FLAG_UPDATE_CURRENT); 16 Y. setLatestEventInfo (this, "coming to message", "one notification", pIntent); 17 manager. Y (10, notify); // send a notification, 10 is the id18} of the notification}

You can call this method in the event of a button. After running the program, click the button to see the notification sent. Layout files and related code are not written here.

 

PendingIntent is the Intent package. Here is the description of the startup Intent. PendingIntent returned by PendingIntent. getActivity

Intent in this PendingIntent instance is the Intent used to start the Activity.

The parameters of PendingIntent. getActivity are Context, and the request code of the sender (0 can be entered) is used for the Intent sent by the system.

PendingIntent. FLAG_UPDATE_CURRENT indicates that if the PendingIntent of the description already exists, the Extra data of the existing PendingIntent is changed to the Extra data of the new PendingIntent.

Intent and PendingIntent:

Intent: indicates the intention, that is, to tell the system what I want to do, and then the system will do the corresponding thing according to this Intent. For example, startActivity is equivalent to sending a message, while Intent is the content of the message.

PendingIntent: Wrap Intent. Intent is our intention to start a job directly using startActivity, startService or sendBroadcast.

In some cases, we cannot directly call startActivity, startServide, or sendBroadcast, but send Intent only when the program or system reaches a certain condition.

For example, after you click Notification, the system sends an Intent of the Activity. Therefore, if we do not need to tell the system in some way, the system does not know that startActivity is used,

StartService or sendBroadcast to start Intent (of course there are other "descriptions"), so PendingIntent is required here.

 


Notification Settings in android

Before you
Notification. defaults = Notification. DEFAULT_LIGHTS;
Later
Notification. defaults = Notification. DEFAULT_VIBRATE;
Therefore, DEFAULT_LIGHTS does not work.

The ringtone mode of a mobile phone is ringtone + no vibration. It should be changed to the ringtone + vibrate mode.

Android: what is the use of Notification when? Not found after the test

System. currentTimeMillis ();
Get the current number of milliseconds
Can be used to test the program running time

The time is calculated when data is read!
Interval of the prompt in the notification bar = s

The three parameters in the notification bar, the icon content, and the occurrence time.
Notification (icon, tickerText, when );
If there is new content in the same notification bar, the update will be determined based on the time.

Related Article

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.