1. Get a reference to the NotificationManager:
2. Instantiate the Notification:
3. Define the Notification's expanded message and Intent:
4. Pass the Notification to the NotificationManager:
User 는 이제 Notification 을 통보 받는다.
출처 : http://developer.android.com/guide/topics/ui/notifiers/notifications.html
1 | String ns = Context.NOTIFICATION_SERVICE; |
2 | NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); |
2. Instantiate the Notification:
1 | int icon = R.drawable.notification_icon; |
2 | CharSequence tickerText = "Hello" ; |
3 | long when = System.currentTimeMillis(); |
4 |
5 |
6 | Notification notification = new Notification(icon, tickerText, when); |
3. Define the Notification's expanded message and Intent:
1 | Context context = getApplicationContext(); |
2 | CharSequence contentTitle = "My notification" ; |
3 | CharSequence contentText = "Hello World!" ; |
4 | Intent notificationIntent = new Intent( this , MyClass. class ); |
5 | PendingIntent contentIntent = PendingIntent.getActivity( this , 0 , notificationIntent, 0 ); |
6 |
7 | notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); |
4. Pass the Notification to the NotificationManager:
1 | private static final int HELLO_ID = 1 ; |
2 |
3 |
4 | mNotificationManager.notify(HELLO_ID, notification); |
출처 : http://developer.android.com/guide/topics/ui/notifiers/notifications.html