티스토리 뷰
안녕하세요 오랜만에 글을 쓰네요
오늘의 포스팅은 Notification 을 사용할시에 알림이 하나오고 다시 오면 제거 되고 새로 갱신되는 않고
이전에 있던걸 지워지지 않고 새로 갱신된게 위로 오는 방식을 알아볼꺼입니다.
제목은 저렇게 적었지만 상활을 적어야되는거라서 참 애매하네요
일단 소프 보실께요
public class MyHandler extends NotificationsHandler {
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
Context ctx;
@Override
public void onReceive(Context context, Bundle bundle) {
ctx = context;
String nhMessage = bundle.getString("message");
sendNotification(nhMessage);
if (MainActivity.isVisible) {
MainActivity.mainActivity.ToastNotify(nhMessage);
}
}
private void sendNotification(String msg) {
Intent intent = new Intent(ctx, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mNotificationManager = (NotificationManager)
ctx.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, (int)(System.currentTimeMillis()/1000),
intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
//bigTextStyle.setSummaryText("...");
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(ctx)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), R.mipmap.ic_launcher))
//.setLargeIcon(R..ic_launcher)
.setContentTitle("Notification Hub Demo")
.setStyle(bigTextStyle
.bigText(msg))
.setSound(defaultSoundUri)
.setDefaults(Notification.FLAG_NO_CLEAR)
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify((int)(System.currentTimeMillis()/1000), mBuilder.build());
}
}
public class MyHandler extends NotificationsHandler {
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
Context ctx;
@Override
public void onReceive(Context context, Bundle bundle) {
ctx = context;
String nhMessage = bundle.getString("message");
sendNotification(nhMessage);
if (MainActivity.isVisible) {
MainActivity.mainActivity.ToastNotify(nhMessage);
}
}
private void sendNotification(String msg) {
Intent intent = new Intent(ctx, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mNotificationManager = (NotificationManager)
ctx.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, (int)(System.currentTimeMillis()/1000),
intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
//bigTextStyle.setSummaryText("...");
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(ctx)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), R.mipmap.ic_launcher))
//.setLargeIcon(R..ic_launcher)
.setContentTitle("Notification Hub Demo")
.setStyle(bigTextStyle
.bigText(msg))
.setSound(defaultSoundUri)
.setDefaults(Notification.FLAG_NO_CLEAR)
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify((int)(System.currentTimeMillis()/1000), mBuilder.build());
}
}
보시면 알겠지만 NotificationManager 에 request 값이 달라야지 Handler의 값을 다르게 인식함으로
이전 데이터를 지워지지 않게 되더라구요
혹시 필요한분들 있을꺼 같아서 포스팅 합니다~~~
'android' 카테고리의 다른 글
[android] 8.0 OREO Notification 알림 대응하기 (2) | 2018.03.20 |
---|---|
[android] encode decode (0) | 2018.02.21 |
[Kotlin] Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter intent (1) | 2017.12.15 |
[android] hybride web에서 webview 자동로그인 (0) | 2017.11.13 |
[android] onCreateWindow not working (2) | 2017.10.17 |
- Total
- Today
- Yesterday
- Sandbox account logout
- Sandbox account sign out
- 맛집
- Swift textField max length
- swift autoclosure
- 위메프
- [WindowScene] Failed to Error
- iPhone X safe area size
- 쇼미더머니6
- swift uitextfield 글자수 제한
- Swift 노치 구분
- Swift app version check
- Swift 앱 버전
- SceneDelegate error
- wwdc21 actor
- Swift version code
- Swift check notch
- Sandbox test login on
- [WindowScene] Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?
- autoclosure
- firebase remote config
- How to get version swift
- swift actor
- Android
- Bundle main infodictionary swift 4
- Swift button underline programmatically
- android notification
- 샤브샤브
- Swift label underline storyboard
- Swift button text underline
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |