// Create a icationicationmanager reference String NS = context. icationication_service; Icationicationmanager mnotificationmanager = (notificationmanager) getsystemservice (NS ); // Define various attributes of notification Int icon = R. drawable. Icon; // notification icon Charsequence tickertext = "hello"; // notification text prompt displayed in the status bar Long when = system. currenttimemillis (); // the time when a notification is generated. It is displayed in the notification information. // Use the above attributes to initialize noication Notification = new notification (icon, tickertext, when ); /* * Add sound * Notification. defaults | = notification. default_sound; * You can also use the following methods: * Notification. Sound = URI. parse ("file: // sdcard/notification/ringer.pdf "); * Notification. Sound = URI. withappendedpath (audio. Media. internal_content_uri, "6 "); * If you want to repeat the sound until the user responds to the notification, you can add "flag_insistent" to the flags field of notification" * If the notification ults field of notification includes the "default_sound" attribute, this attribute overwrites the sound defined in the sound field. */ /* * Add vibration * Notification. defaults | = notification. default_vibrate; * You can also define your own vibration mode: * Long [] vibrate = {0,100,200,300}; // vibration starts after 0 milliseconds. The vibration stops after 100 milliseconds, and then the vibration starts again after 200 milliseconds. * Notification. vibrate = vibrate; * The long array can be defined as any desired length. * If the notification ults field of notification includes "default_vibrate", this attribute overwrites the vibration defined in the vibrate field. */ /* * Add LED light reminder * Notification. defaults | = notification. default_lights; * You can use your own led reminder mode: * Notification. ledargb = 0xff00ff00; * Notification. ledonms = 300; // Bright Time * Notification. ledoffms = 1000; // destroy time * Notification. Flags | = notification. flag_show_lights; */ /* * More feature attributes * Notification. Flags | = flag_auto_cancel; // click this notification in the notification bar and the notification is automatically cleared. * Notification. Flags | = flag_insistent; // repeat the sound until the user responds to the notification. * Notification. Flags | = flag_ongoing_event; // put the notification to the "ongoing" group in the notification bar, that is, "running ". * Notification. Flags | = flag_no_clear; // indicates that the notification is not cleared after you click "clear notification" in the notification bar, * // Often used with flag_ongoing_event * Notification. Number = 1; // The number field indicates the number of current events represented by this notification. It will overwrite the status bar icon * // To use this field, it must start from 1. * Notification. iconlevel = ;// */ // Set the notification event message Context context = getapplicationcontext (); // Context Charsequence contenttitle = "my notification"; // the title of the notification bar Charsequence contenttext = "Hello world! "; // Notification bar content Intent notificationintent = new intent (this, Main. Class); // click the activity to jump to after the notification Pendingintent contentintent = pendingintent. getactivity (this, 0, icationicationintent, 0 ); Notification. setlatesteventinfo (context, contenttitle, contenttext, contentintent ); // Pass the notification to icationicationmanager Micationicationmanager. Y (0, notification ); |