Android Notification related API record

Source: Internet
Author: User

API for recording post notifications (Notification)

1. Use the Getsystemservice () method to get the system service, the parameter receives a string to determine the specific service to use, the notification is passed into the Content.notification_service

Example: Notificationmanager manger = (Notificationmanager) getsystemservice (Content.notification_service);

2. Use the Notificationcompat.builder () constructor to create a notification object and add its required properties using concatenating, and the Builder () parameter receives a context

Example: Notification Notification = new Notificationcompat.builder (context)

. Setcontenttitle ("This is the title of the Notification")

. Setcontenttext ("This is the content of the notification")

. Setsmalicon (The resource address of the small icon for incoming notification bar)

. Setlargeicon (The resource address of the large icon for incoming notifications)

. build ();

Finally, build with build ().

Then use Manger.notify () to have the notification appear, this method receives two parameters, the first is the ID specified for each notification, and the second is the notification object.

Here are some setxxx methods that need to be concatenating before build ():

    • The Setcontentintent () method receives a Pendingintent object (Ps:pendingintent is the intention we want when we click the notification)
    • The Setautocancel () method receives a Boolean variable that passes in true to indicate that it disappears automatically when the notification is clicked
    • The Setsound () method receives a URI parameter that plays a piece of audio when the notification is emitted
    • The Setvibrate () method receives an array of long shapes, with the subscript starting at 0 alternating to indicate fine length and vibration duration, in milliseconds. Use this property to be sure to go to Androidmanifest.xml to declare permissions <uses-permission android:name= "Android.permission.VIBRATE"/>
    • The Setlights () method receives three parameters that specify the color of the first parameter of the LED light the second parameter specifies the length of time the third parameter specifies that the length of the darkness is also in milliseconds
    • The SetDefaults () method specifies the standard default notification effect, passing in Parameters Notificationcompat.default_all
    • The SetStyle () method is used to enrich the use of notification, can be displayed in the notification of large text and pictures, etc., see detailed documents
    • The SetPriority () method sets the priority of the notification, and the parameter receives 5 constant values, corresponding to 5 priority levels from low to high
      • 1. Priority_min
      • 2. Priority_low
      • 3. Priority_default
      • 4. Priority_high
      • 5. Priority_max

Well, temporarily recorded here, later if the use of new API properties, the author will promptly update this article.

  

Android notification related API records

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.