Android Recall record notification bar

Source: Internet
Author: User

Notification Bar

Set Reminder flags Flags
Features:
Reminder markers, add sounds to notifications, flashing lights and vibration effects settings to notify the notification effect, you can combine multiple properties
Usage method (one):
Notification notify = Mbuilder.build ();
Notify.flags = notification.flag_auto_cancel;//
Reminder marker Member:
Notification.flag_show_lights//Tri-Color light reminder, This flag must be added when using a tri-color lamp reminder
Notification.flag_ongoing_event//initiating a running event (active)
Notification.flag_insistent//Let sound, vibration infinite loop Until the user responds (cancels or opens)
Notification.flag_only_alert_once//Notification, the ringtone and vibration are performed only once
Notification.flag_auto_ CANCEL//The user automatically disappears after clicking the notification
Notification.flag_no_clear//Only clear the Notification, not clear the notification (QQ notification can not be cleared, is used this)
Notification.flag_foreground_service//Indicates a running service
Attached:
Use Method (second):
Notificationcompat.builder mbuilder = new Notificationcompat.builder (this);
Pendingintent pendingintent= pendingintent.getactivity (this, 1, new Intent (), flags);
Mbuilder.setcontentintent (pendingintent intent);

Add sound, strobe, and vibration effects to notifications
Function:
The simplest and most consistent way to add a sound, strobe, and vibration effect to a notification is to use the Defaults property using the current user default settings.
You can combine multiple properties.
How to use:
Notificationcompat.builder Mbuilder = new Notificationcompat.builder (this);
Mbuilder.setdefaults (notification.default_lights| Notification.default_sound);//Do not set this [bell, flashing lights, vibration] will not be executed, but quiet.
corresponding attributes:
Notification.default_vibrate//Add default vibration reminder requires vibrate permission
Notification.default_sound//Add default sound alerts
notification.default_lights//Add a default tri-color light reminder
notification.default_all//Add a default of 3 full reminders
Do not set//This [bell, flashing, vibration] will not be executed, but quiet.

Set the vibration mode
Usage method (one):
Notificationcompat.builder Mbuilder = new Notificationcompat.builder (this);
Mbuilder.setvibrate (new long[] {0,300,500,700});
How to use (second):
Notification notify = Mbuilder.build ();
Notify.vibrate = new long[] {0,300,500,700};
Effect:
Delay 0ms, then vibrate 300ms, in delay 500ms, then in vibration 700ms.

Tri-Color Lamp reminder
Function:
Android supports three-color lamp reminders, this method is to set different scenes under different colors of the lights.
Usage method (one):
Mbuilder.setlights (0XFF0000FF, 300, 0);
How to use (second):
Notification notify = Mbuilder.build ();
Notify.flags = notification.flag_show_lights;
Notify.ledargb = 0xff0000ff;
NOTIFY.LEDONMS = 300;
NOTIFY.LEDOFFMS = 300;
Describe:
Where Ledargb represents the light color, Ledonms light duration, ledoffms dark time.
Attention:
1) A tri-color light reminder is only supported when the flag is set to Notification.flag_show_lights.
2) This side of the color with the device, not all colors can be, to see the specific equipment.

Set Reminder Sounds
Usage method (one):
Set Default ringtone
Mbuilder.setdefaults (Notification.default_sound);
Set a custom ringtone
Mbuilder.setsound (Uri.parse ("File:///sdcard/xx/xx.mp3"));
Get ringtones inside the Android multimedia library
Mbuilder.setsound (Uri.withappendedpath (Audio.Media.INTERNAL_CONTENT_URI, "5"));
How to use (second):
Notification notify = Mbuilder.build ();
Notify.sound = Uri.parse ("File:///sdcard/xx/xx.mp3");

Setting the priority level
Usage method (one):
mbuilder.setpriority (int pri);
How to use (second):
Notification notify = Mbuilder.build ();
notify.priority = Notification.priority_default;
Optional properties:
Notification.priority_default
Notification.priority_high
Notification.priority_low
Notification.priority_max
Notification.priority_min

In-Progress notifications
Usage method (unique):
Mbuilder.setongoing (FALSE);
Function:
Set to Ture, which indicates that it is an in-progress notification.
They are usually used to indicate a background task where the user is actively involved (such as playing music) or is waiting in some way, thus occupying the device (such as a file download, synchronous operation, active network connection).

Progress bar
Function:
Set up a notification with a progress bar that you can use in your download.
Usage method (unique):
mbuilder.setprogress (int max, int progress,boolean indeterminate)

Response [ click , Delete , emergency ] Events
Method (one):
Click
Mbuilder.setcontentintent (pendingintent intent);
Empty
Mbuilder.setdeleteintent (pendingintent intent);
Responding to emergency events
Setfullscreenintent (Pendingintent Intent, Boolean highpriority)
Method (second):
Notification notify = Mbuilder.build ();
Notify.contentintent: In the Notification window area, the response event notification when clicked is triggered by the intent;
Notify.deleteintent: Responds to the intent of the purge event when the user clicks the Clear All button;
Notify.fullscreenintent: A full-screen event in response to a state of emergency (such as a call event), that is, when the notification comes in, skip clicking the notification in the notification area and directly execute the event fullscreenintent represents.
Report:
The bit identifier for the pendingintent:
Flag_one_shot indicates that the returned pendingintent can only be executed once and automatically canceled after execution
Flag_no_create indicates that if the description of the pendingintent does not exist, the corresponding pendingintent is not created, but returns null
Flag_cancel_current indicates that the corresponding pendingintent already exists, cancels the former and then creates a new pendingintent, which facilitates the data to remain up-to-date and can be used for communication scenarios of instant communication
Flag_update_current represents the updated pendingintent

How to cancel notifications on the notification bar

1. Set the corresponding flags so that the user clicks are eliminated:
Notification.flags = flag_auto_cancel;
2. By manually eliminating an item or all notification
Mnotificationmgr.cancle (notification_id);//clear the corresponding ID of the notification
Mnotificationmgr.cancleall ();// Eliminate all notifications that are created

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.