0
앱이 실행 중이거나 백그라운드에서 죽거나 fcm 알림을 처리하는 패턴을 찾고 있습니다.실행 중일 때 FCM 알림 처리
우리 앱에는 로그인 프로세스가 있기 때문에 앱이 실행되지 않을 때 알림은 런처를 열어야하지만 앱이 실행 중일 때 사용자가 알림을 클릭하면 활동을 푸시하고자합니다.
그래서 가장 좋은 방법은 ContentIntent가 스택의 최상위 활동으로 전달되거나 Launch-Activity로 전달되는 것입니다.
현재 실행 중인지 여부에 관계없이 현재 코드는 항상 TaskStackBuilder로 앱을 다시 시작합니다.
내 코드의 샘플 : AndroidManifest를에 singleInstance 같은 MyProfileActivity의 launchMode를 설정하는
resultIntent = new Intent(this, MyProfileActivity.class);
resultIntent.putExtra(ActivityUtil.KEY_IMAGE_URL, SharedPref.getUserImage(this));
resultIntent.putExtra(KEY_NOTIFICATION_ID, notificationID);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(SetDetailReworked.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "...")
.setLargeIcon(getBitmapFromUrl(images[UI.GetDensityInt(this)]))
.setSmallIcon(R.drawable.bar_icon)
.setContentTitle(getString(R.string.push_notification_Title))
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(resultPendingIntent);
Notification not = builder.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(ID, not);