Simple Android Notification application

Source: Internet
Author: User

Simple Android Notification application

Notification is a Notification displayed in the mobile phone status bar. The mobile phone status bar is located at the top of the mobile phone screen, where the current network status, battery status, and time of the mobile phone are usually displayed. The Notification lock indicates a global Notification. A program generally sends a Notification through the icationicationmanager service.

 

MainActivity. java

 

Public class MainActivity extends Activity {final int NOTIFICATION_ID = 1; icationicationmanager nm; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); nm = (icationicationmanager) getSystemService (icationication_service);} public void send (View view) {Intent intent = new Intent (MainActivity. this, NextActivity. class); // PendingInt An Intent is encapsulated in the ent, which means the PendingIntent pi = PendingIntent. getActivity (MainActivity. this, 0, intent, 0); Builder builder = new Notification. builder (MainActivity. this); // set to enable this Notification, which automatically disappears notification Notification = builder. setAutoCancel (true) // set the notification message displayed in the status bar. setTicker (with new messages) // sets the small notification icon. setSmallIcon (R. drawable. ic_launcher) // sets the title of the notification content. setContentTitle (the title of the notification content) // sets the notification content. setContentText (Notification content ............) // Set the default system sound and the default LED light. setDefaults (Notification. DEFAULT_SOUND | Notification. DEFAULT_LIGHTS) // sets the Intent to be started for notification. setContentIntent (pi ). build (); // After the configuration is complete, send the notification nm. Y (ication_id _id, notification);} public void cancel (View view) {// cancel the notification nm Based on the specified ID. cancel (icationication_id );}}
If you do not want to use the default settings, you can also use the following code:

 

 

// Set custom sound setSound (Uri. parse (file: // sdcard/clickwheel); // setVibrate (new long [] {100,150 });

:

 

 

Do you have any questions? Why should AlertDialog. Builder be written in internal classes? This is the builder mode (separating a complex build from its representation so that different representations can be created for the same build process. In other words: it means to separate an object from how to build this object. If you want to build an object, you will tell this message to the builder, and inform the builder of the various requirements on this object, and then the builder according to these requirements

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.