android-User Alert notification

Source: Internet
Author: User

android-user alert notification a Notification
Notification: Typically hardware-related features are used in Systemservice (trace source)

Operation Steps:
1 Defining Notificationmanager Objects
Private Notificationmanager Mnotificationmanager;

2 Instantiating a Notificationmanager object
Mnotificationmanager = (Notificationmanager) getsystemservice (Notification_service);

3 Constructing a Notification object and instantiating it
Notification _notification = new Notification

4 Setting event Information
Pendingintent _pendintent = pendingintent.getactivity ()

5 Opening notification
Mnotificationmanager.notify (123, _notification); 123 Unique ID for notifications

Use of Pendingintent:
itself is not intent-design mode for single-piece mode (construction mode) (only one instance is returned with the instance method, often used to control the different types of an instance)
Pendingintent _pendintent = pendingintent.getactivity (
0,//If the active activity requires a return value, the request code must have a value
New Intent (Mynotifiationactivity.this, Menutestactivity.class),//intent object
0);//flag Mark

two custom notification:
1 Vibrations:
Default system Notification.defaults |= notification.default_vibrate;
Long[] vibrate = {0,100,200,300};
Notification.vibrate = Vibrate
Manifest file to add permissions <uses-permission android:name= "Android.permission.VIBRATE"/>

2 Sound:
Default system Notification.defaults |= Notification.default_sound;
Custom Notification.sound = Uri.parse ("****ringer.mp3");

3 Flash:
Default system Notification.defaults |= notification.default_lights;
Notification.ledargb = 0xff00ff00; Flash color
NOTIFICATION.LEDONMS = 300; turn on time
NOTIFICATION.LEDOFFMS = 1000; Closing time
Notification.flags |= notification.flag_show_lights; Set flags

4 Layout of notifications:
In order to customize the layout of the notification, first instantiate remoteviews to create a layout file and then pass the remoteviews to notification's Contentview property

You also need to set intent
_notification.contentintent = _pendintent;

The next step is to press the object instance into the XML itself, before the default _notification.setlatesteventinfo method can no longer be used
_notification.contentview = new Remoteviews (Getpackagename (), r.layout.layout_customnotifiation);

Note: r.layout.layout_customnotifiation); For a custom layout file, do not let your custom layout be too complex to be sure to test it on a different configuration.

three notification and flags (flags) to customize for your own notifications
Use Notification.flags |= notification.flag_auto_cancel

Flag_auto_cancel logo
Use this flag to let the notification prompt disappear automatically after the notification is selected.

Flag_insistent logo
Using this flag, you can let the Beep loop play until the user responds.

Flag_ongoing_event logo
With this tag, you can make the notification a notification for a running app. This means that the app is still running-its process is still running in the background, even when the app is not visible in the foreground (like music playback and phone calls).

Flag_no_clear logo
Use this flag to indicate that the notification must be cleared through the "Clear Notifications" button. This is useful if your app is still running.

Number Property
The value of this property that indicates the number of current notifications. This number is displayed on the icon for the status notification. If you want to use this property, then when the first notification is created, its value starts at 1. Rather than zero.

The value of this attribute indicates the current level of the levellistdrawable. You can animate the notification icon on the status bar by changing its value to be associated with the drawable defined by levellistdrawable.

android-User Alert notification

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