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