}When you click the button, the status bar displays:
VcHLsMmjrNe0zKzAuLbgs/routing + CjxpbWcgc3JjPQ = "http://www.2cto.com/uploadfile/Collfiles/20140517/20140517091102107.gif" alt = "\">
Then, when we click this dialog box, intent will be triggered and jump to icationication2activity. java.
Bytes ----------------------------------------------------------------------------------------
Note: The id in notify (id, notification) in icationicationmanager is the identifier used to uniquely identify our current notification. This value is passed when we delete a notification through the cancel method. When reading many documents, readers may find that this place has specified an inexplicable value, such as R. drawable. I am wondering why I want to specify an image here. Here I will introduce why?
The answer is actually very simple. We all know that the only requirement for the parameter here is that the id must be consistent with and unique in the notify method. If the two parameters are met, nothing else. Notify and cancel are consistent. as developers, we are very easy to control, but the only one is that we can't really say it, so here some people are thinking about it, we use the index IDs of image resources or other resources in our system. We all know that these values must be unique!
Bytes ------------------------------------------------------------------------------------------
The following are some materials from the Internet:
To add a Notification, follow these steps:
1: Obtain icationicationmanager:
Icationicationmanager m_NotificationManager = (NotificationManager) this. getSystemService (icationication_service );
2: Define a Notification:
Notification m_Notification = new Notification ();
3: set various attributes of Notification:
// Set the icon of the notification displayed in the status bar
M_icationication.icon = R. drawable. icon;
// Content displayed when we click the notification
M_icationication.tickertext = "Button1 notification content .....";
Default sound sent during notification
M_icationication.defaults = Notification. DEFAULT_SOUND;
// Set the notification display parameters
Intent m_Intent = new Intent (icationicationdemo. this, DesActivity. class );
PendingIntent m_PendingIntent = PendingIntent. getActivity (icationicationdemo. this, 0, m_Intent, 0 );
M_icationication.setlatesteventinfo (icationicationdemo. this, "Button1", "Button1 notification", m_PendingIntent );
// This can be understood as starting to execute this notification
M_icationicationmanager.policy (0, m_Notification );
4: Now that you can add or delete it. Of course, it is just to delete what you add.
M_icationicationmanager.cancel (0 );
Here 0 is an ID number, which is the same as the first parameter 0 of policy.
This completes adding and deleting.
Bytes ------------------------------------------------------------------------------------------------------
NoticificationManager can be easily placed in the status bar, and it is easy to access the program from statusbar,
In NoticificationManager, you can use intent to execute the activity of this program.
NoticificationManager status bar operation
Icationicationmanager (Notification manager ):
Icationicationmanager is responsible for notifying users of events.
Icationicationmanager has three common methods:
1. cancel (int id) cancels a previously displayed notification. If it is a short notification, it tries to hide it. If it is a persistent notification, it will be removed from the status bar.
2. cancelAll () cancels all previously displayed notifications.
3. Y (int id, Notification notification) permanently sends the Notification to the status bar.
// Initialize icationicationmanager:
Icationicationmanager nm =
(Icationicationmanager) getSystemService (NOTIFICATION_SERVICE );
Notification indicates a Notification.
Notification attributes:
AudioStreamType the type of the audio stream used when the sound starts
When a notification entry is clicked, contentIntent executes the configured Intent.
ContentView: When a notification is displayed on the status bar, the configured view is also displayed.
Defaults specifies the value to be set to the default value.
DeleteIntent when you click the "Clear All Notifications" button to delete All Notifications, the configured Intent is executed.
The image used by the icon status bar.
IconLevel if there are several levels of Status Bar images, set it here.
LedARGB LED light color.
Flash time when ledOffMS LED is disabled (in milliseconds)
Flash time when ledOnMS LED starts (in milliseconds)
Number indicates the number of the event.
Sound notification sound
Information displayed when the tickerText notification is displayed in the status bar
Vibrate vibration mode.
The timestamp of the when notification.
Send Notification to status bar:
Notification notification = new Notification ();
Notification setting process ........
Nm. Y (0, notification); // it is sent to the status bar.
Bytes ------------------------------------------------------------------------------------------------------------
Notification provides a wide range of mobile phone prompts:
A) notification text prompts displayed in the Status Bar, such:
Notification. tickerText = "hello ";
B) make a prompt, for example:
Notification. defaults = Notification. DEFAULT_SOUND;
Notification. sound = Uri. parse ("file: // sdcard/notification/ringer.pdf ");
Notification. sound = Uri. withAppendedPath (Audio. Media. INTERNAL_CONTENT_URI, "6 ");
C) Mobile Phone vibration, such:
Notification. defaults = Notification. DEFAULT_VIBRATE;
Long [] vibrate = {0,100,200,300 };
Notification. vibrate = vibrate;
D) LED light flashes, such:
Notification. defaults = Notification. DEFAULT_LIGHTS;
Notification. ledARGB = 0xff00ff00;
Notification. ledOnMS = 300;
Notification. ledOffMS = 1000;
Notification. flags = Notification. FLAG_SHOW_LIGHTS;
4) send notifications:
Private static final int ID_NOTIFICATION = 1;
Micationicationmanager. Y (ID_NOTIFICATION, notification );
Application Instance 3-combined with Broadcast and Broadcast Receiver
private static final String ACTION_1="com.example.androidbasicdemo1.NEW_BROADCAST_1";private static final String ACTION_2="com.example.androidbasicdemo1.NEW_BROADCAST_2";
@ Overridepublic boolean onCreateOptionsMenu (Menu menu) {menu. add (0, Menu. FIRST, 0, "display Notification"); menu. add (0, Menu. FIRST + 1, 0, "clear Notification"); return super. onCreateOptionsMenu (menu) ;}@ Overridepublic boolean onOptionsItemSelected (MenuItem item) {int id = item. getItemId (); if (id = Menu. FIRST) {actionClickMenuItem1 (); return true;} if (id = Menu. FIRST + 1) {actionClickMenuItem2 (); return true;} return super. onOptionsItemSelected (item);} private void actionClickMenuItem1 () {Intent intent1 = new Intent (ACTION_1); sendBroadcast (intent1);} private void actionClickMenuItem2 () {Intent intent2 = new Intent (ACTION_2); sendBroadcast (intent2 );}
Broadcast Receiver1
Package com. example. broadcastreceiver; import com. example. androidbasicdemo1.DBDemoActivity; import android. r; import android. app. notification; import android. app. icationicationmanager; import android. app. pendingIntent; import android. content. broadcastReceiver; import android. content. context; import android. content. intent;/*** must be in AndroidManifest. register in xml * Custom Broadcast Receiver er inherits BroadcastReceiver * override onReceive () method ** @ author JayHe **/public class MyAndroidReceiver1 extends BroadcastReceiver {private Context context Context; public static int NOTIFICATION_ID = 21321; @ Overridepublic void onReceive (Context context, Intent intent) {this. context = context; showNotification ();} private void showNotification () {icationicationmanager icationmanager = (icationicationmanager) context. getSystemService (android. content. context. NOTIFICATION_SERVICE); Notification notification = new Notification (R. drawable. ic_btn_speak_now, "From MyReceiver1", System. currentTimeMillis (); PendingIntent contentIntent = PendingIntent. getActivity (context, 0, new Intent (context, DBDemoActivity. class), 0); notification. setLatestEventInfo (context, "In MyReceiver1", null, contentIntent); icationicationmanager. Y (ication_id _id, notification );}}
Broadcast Receiver2Package com. example. broadcastreceiver; import android. app. icationicationmanager; import android. content. broadcastReceiver; import android. content. context; import android. content. intent; public class MyAndroidReceiver2 extends BroadcastReceiver {Context context; @ Overridepublic void onReceive (Context context, Intent intent) {this. context = context; deleteNotification ();} // The enotification method returns the generated Notificatio N is deleted from the status bar. /*** Note: each Notification has a unique id, and the id of this Notification in the program is MyAndroidReceiver1.NOTIFICATION _ ID */private void deleteNotification () {icationicationmanager icationmanager = (NotificationManager) context. getSystemService (android. content. context. NOTIFICATION_SERVICE); icationicationmanager. cancel (MyAndroidReceiver1.NOTIFICATION _ ID );}}