Android Notification-android Learning Journey (ii)

Source: Internet
Author: User

Notification is commonly used in pull-down message pushes.

The composition of the notification

Examples of nitification

1. Create a new builder to select the Notification.compat package.
2. Then use Builder to set the properties of the nitification.
Code:

 Public  class mainactivity extends Activity {     Public Static Final intnotification_id = $;intCount =0;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main); Findviewbyid (R.id.button1). Setonclicklistener (NewOnclicklistener () {@Override             Public void OnClick(View v) {//TODO auto-generated method stubcount++; Builder Builder =NewNotificationcompat.builder (mainactivity. This);                Builder.setsmallicon (R.drawable.ic_launcher); Builder.setcontenttitle ("Oh, wow!" You have the message of Count's heart.); Builder.setcontenttext ("Notification created successfully");                Notification Notification = Builder.build ();                Notificationmanager manager = (Notificationmanager) getsystemservice (Context.notification_service);            Manager.notify (notification_id, NOTIFICATION);    }        }); }}

NOTIFICATION_ID This constant value is used to uniquely identify the NOTIFICATION.
This notification can be updated directly with each update. Builder can set more properties.

Android Notification-android Learning Journey (ii)

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.