Detailed explanation of notification notification usage developed by Android

This article illustrates the usage of notification notification developed by Android. Share with you for your reference, as follows:

According to the life cycle of the activity, when the activity is not displayed, the onstop function will be executed (for example, press the home key), so you put the notification in the notification bar in the onstop function (except pressing the exit key), and then remove the notification from the notification bar when it is displayed. Alternatively, the notification bar icon is always displayed as long as the program is running.

Here are some constants, fields and methods in the notification class:

Constant:

DEFAULT_ All uses all default values, such as sound, vibration, flashing, etc. default_ Lights uses the default flash prompt default_ Sounds uses the default prompt sound default_ Vibrate uses the default phone shake

[note]: to add mobile phone vibration, you must add permissions in manifest.xml:

The above effect constants can be superimposed, that is, through

notification.defaults |= DEFAULT_ Sound (it is better to test on the real machine, but not on the vibration effect simulator)

Set flag bit

FLAG_ AUTO_ Cancel this notification can be cleared by the clear button on the status bar_ NO_ Clear this notification can be cleared by the clear button on the status bar_ ONGOING_ The event notification is placed in the running flag_ Whether the insistent is always on, for example, the music is always playing, and the user's response is known

Common fields:

Contentintent sets the pendingintent object and sends the intent defaults when clicked. Add the default effect flags and set the flag bit, such as flag_ NO_ Clear and other icon settings Icon sound sets the text of sound tickertext displayed in the status bar when the timestamp of this notification is sent

Introduction to common methods of notificationmanager:

Public void cancelall() removes all notifications (only for notifications under the current context) public void cancel (int ID) removes notifications marked with ID (only for all notifications under the current context) public void notify (string tag, int ID, notification) adds notifications to the status bar, labeled with tag and marked with ID public void notify (int ID, notification notification) add the notification to the status bar and mark it as ID

For more Android related content, readers who are interested can view the topics on this site: summary of Android basic component usage, summary of Android view skills, summary of Android resource operation skills, summary of Android file operation skills, summary of Android SQLite database operation skills, summary of Android JSON format data operation skills Summary of Android database operation skills, summary of SD card operation methods for Android programming development, introduction and advanced tutorial for Android development, summary of activity operation skills for Android programming and summary of Android control usage

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>