티스토리 뷰
전에 Notification을 버전에 따라서 다르게 띄우는 방법에 대해서, 알아보았다.
이번에는, Notification을 이용하는 여러가지 방법에 대해서 알아보도록 하자.
1. Notification에 FLAG_AUTO_CANCEL flag를 설정해주면, 해당 Notification이 click되면, 자동으로 사라진다.
2. Notification의 sound추가는 notification.defaults에 한다.
EX) notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3");
3. Notification sound가 계속 울려야 할 경우에는 FLAG_INSISTENT를 사용
4. notification.defaults에 DEFAULT_SOUND 값이 존재하면, 다른 값들은 모두 무시되고 이 값이 유효하다.
5. vibration도 notification.defaults에 설정한다. vibration pattern은 notification.vibrate에 long[] 값을 넣어주도록 한다.
6. notification.defaults에 DEFAULT_VIBRATE 값이 존재하면, 다른 값들은 모두 무시되고 이 값이 유효하다.
8. notification led control 은 notification.ledARGB, ledOnMs, ledOffMs, 로 control 하며 flag 는 Notification.FLAG_SHOW_LIGHTS 를 설정해 주어야 한다.
9. FLAG_ONGOING_EVENT flag 가 설정되면, OnGoing 이라는 title 을 가진 notification window 에 notification 이 등록된다. ( 예 : 다운로드 )
10. FLAG_NO_CLEAR 는 notification bar 의 "clear" 버튼에 의해 clear 되지 않는다.
11. notification.number 는 event 의 갯수를 나타낸다. number 값은 1부터 시작해야 한다. 0부터 시작되면 1,2 로 올라도 표시 되지 않는다.
12. notification.iconLevel 은 Drawable 들을 LevelListDrawable 에 명시하고, 이 drawable 을 바탕으로 notification icon 을 animation 한다.
13. Notification 에 Custom View 를 적용할 때, style 을 사용하는 것이 좋다. 안드로이드 framework 마다 Notification 의 배경색이 다를 수 있기 때문이다. Android 2.3 부터는 default notification layout 에 대한 style을 제공한다. 이 default style 을 사용하면 쉽게 배경색과 어울릴 수 있다.
14. Notification 에 custom layout 을 적용할 경우에는, 공간제약이 있기 때문에 더 주의를 기울여야 한다. orientation 등의 여러가지 환경에서 제대로 표시되는지 반드시 확인해야 한다.
* Notification Style Source
<!-- 2.3미만 -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NotificationText">
<item name="android:textColor">?android:attr/textColorPrimary</item>
</style>
<style name="NotificationTitle">
<item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textStyle">bold</item>
</style>
<!-- If you want a slightly different color for some text,
consider using ?android:attr/textColorSecondary -->
</resources>
<!-- 2.3이상 -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NotificationText" parent="android:TextAppearance.StatusBar.EventContent" />
<style name="NotificationTitle" parent="android:TextAppearance.StatusBar.EventContent.Title" />
</resources>
'Mobile > Android' 카테고리의 다른 글
| [Android]Volley (0) | 2014.08.19 |
|---|---|
| 안드로이드 4.4 (Kitkat) 이상에서 외부 저장소 사용하기 (0) | 2014.08.19 |
| Resource를 Bitmap만들기 (0) | 2014.08.11 |
| Notification (0) | 2014.08.11 |
| Drawable to Bitmap (0) | 2014.08.08 |
- Total
- Today
- Yesterday
- php
- rxswift
- enum
- Spring
- Linux
- Java
- Python
- windows10
- war
- go
- Kotlin
- Windows
- golang
- ios
- intellij
- git
- nodejs
- github
- MySQL
- tomcat
- android
- SWIFT
- Gradle
- Xcode
- cocoapods
- Codable
- centos8
- ubuntu
- CentOS
- docker
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |