Notification
Notification 과 관련해서는 아래의 문서가 가장 자세히 나온 듯 하다. example 도 같이 보여주며서 설명 해 준다. 문서의 목차는 아래와 같다.Notifying the User | Android Developers
그밖에...
4.1 이전의 status bar 에 대한 설명 : Status Notifications | Android DevelopersNotification 이미지
Image from Notifications | Android Developers |
- Content title
- Large icon(Large icon size)
- Content text
- Content info
- Small icon
- Time
- Details area
- Big picture style
The details area contains a bitmap up to 256 dp tall in its detail section. - Big text style
Displays a large text block in the details section. - Inbox style
Displays lines of text in the details section.
Big view 스타일(Big picture style, Big text Style, Inbox style) 에서만 가능한 기능
- Big content title
- Summary text
반드시 설정해야 하는 부분(Required notification contents)
- A small icon, set by setSmallIcon()
- A title, set by setContentTitle()
- Detail text, set by setContentText()
Example
Notification noti = new Notification.Builder(this) .setContentTitle(title) .setContentText(text) .setSmallIcon(R.drawable.stat_sample) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.stat_sample)) .setContentInfo(getText(R.string.mp3player_content_info)) .setContentIntent(contentIntent) .build(); // Send the notification. ((NotificationManager)getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION, noti);
NotificationCompat
Compatibility
https://developer.android.com/guide/topics/ui/notifiers/notifications.html#Compatibility하위 호환성을 위해 NotificationCompat 를 제공한다.
Example
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle() .addLine( "M.Twain (Google+) Haiku is more than a cert...") .addLine("M.Twain Reminder") .addLine("M.Twain Lunch?") .addLine("M.Twain Revised Specs") .addLine("M.Twain ") .addLine( "Google Play Celebrate 25 billion apps with Goo..") .addLine( "Stack Exchange StackOverflow weekly Newsl...") .setBigContentTitle("6 new message") .setSummaryText("mtwain@android.com"); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.stat_sample) .setContentTitle(title) .setContentText(text) .setStyle(style); Notification noti = mBuilder.build(); noti.flags |= Notification.FLAG_NO_CLEAR; // Send the notification. ((NotificationManager)getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION, noti);
Action
Example
Intent intent = new Intent(this, NotificationReceiverActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.stat_sample) .setContentTitle("Content Title") .setContentText("Contetn Text") .addAction(R.drawable.stat_sample, "added action", pIntent) .setContentIntent(pIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, mBuilder.build());
addAction()
addAction 을 하면 버튼이 추가된다. 이 버튼을 눌렀을 때의 동작을 set 해준다.setContentIntent()
setContentIntent() 는 notification panel 에서 notification 을 click 했을 때 실행된다.Customization
RemoteViews
자신이 원하는 모양으로 notification 을 보여주고 싶다면 RemoteViews 를 이용하자. 이 녀석을 new 해서 Notification 의 bigContentView 나 contentView 에 assign 해주면 된다.
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.stat_sample) .setContentTitle(title) .setContentText(text) .setContentIntent(contentIntent); Notification noti = mBuilder.build(); RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.mp3player_notification); expandedView.setOnClickPendingIntent(R.id.noti_image, contentIntent); expandedView.setOnClickPendingIntent(R.id.noti_button_play, contentIntent); noti.bigContentView = expandedView;
mBuilder.setContentIntent() 는 notification 전체에 대한 것이고,
setOnclickPendingIntent() 는 각각의 View 에 지정해 줄 수 있다.
댓글 없음:
댓글 쓰기