티스토리 뷰
버전에 따라서 Notification을 사용못하도록 조정하였다.
그래도 구글측에서 사용할수 있도록 클래스를 만들어주었다.
아래와 같음...
void showAppNotification() {
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = null;
final int icon = R.drawable.ic_launcher;
final CharSequence ticker = "I got";
final CharSequence title = "mrgamza";
final CharSequence message = "Test";
PendingIntent contentIntent;
if(Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
Intent[] intents = new Intent[2];
intents[0] = Intent.makeRestartActivityTask(new ComponentName(getApplicationContext(), MainActivity.class));
intents[1] = new Intent(getApplicationContext(), MainActivity.class);
intents[1].putExtra("TestExtra", "Extra");
contentIntent = PendingIntent.getActivities(this, 0, intents, PendingIntent.FLAG_CANCEL_CURRENT);
}
else {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("TestExtra", "Extra");
contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
builder.setContentTitle(title);
builder.setContentText(message);
builder.setSmallIcon(icon);
builder.setTicker(ticker);
builder.setContentIntent(contentIntent);
builder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap));
notification = builder.build();
notification.defaults = Notification.DEFAULT_ALL;
notificationManager.notify(0, notification);
}
위의 내용에서 하위버전의 경우에는 Activity가 유일하게 동작을 하여야 할것이다.
추가적인 부분으로는 이렇게 추가해도 될듯...
activity 에 launchMode="singleTask", android:taskAffinity="", android:excludeFromRecent="true" 를 옵션으로 주도록 한다.
안타깝게도 위와같이 지정을 하여도, 4.1 하위 버전에서는 크게 안나온다.
상세사항.
http://developer.android.com/training/notify-user/expanded.html
'Mobile > Android' 카테고리의 다른 글
| Notification에 대하여. (0) | 2014.08.13 |
|---|---|
| Resource를 Bitmap만들기 (0) | 2014.08.11 |
| Drawable to Bitmap (0) | 2014.08.08 |
| 다른앱의 리소스를 가져와서 사용 (0) | 2014.08.08 |
| 어플 설치 여부 확인 (0) | 2014.08.08 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- Windows
- windows10
- Codable
- php
- Python
- Java
- Linux
- enum
- git
- ios
- cocoapods
- Xcode
- golang
- ubuntu
- Spring
- MySQL
- rxswift
- centos8
- war
- intellij
- Gradle
- github
- go
- CentOS
- SWIFT
- Kotlin
- nodejs
- android
- docker
- tomcat
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함