마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

[Android] FCM push를 받아 Noti에서 Click할때.

0 추천
안녕하세요!.

현재 FCM push를 noti로 받아 noti를 Click시 PendingIntent를 주어 MainActivity로 이동하게 구현이 되어 있습니다.

 

여기서 궁금한점이 한가지 있습니다.

Noti -> MainActivity로 넘어갈떄 MainAcitity위에  AlertDialog를 띄워주고 싶은데 혹시 방법이나 skill 있을까요?

일반적으로 app을 실행할때는 AlertDialog가 뜰 필요가 없고, FCM push noti Click하여  main으로

들어올때만 해당 AlertDialog를 띄어주고 싶습니다.

 

조언 부탁드립니다. 감사합니다.
김트릿 (380 포인트) 님이 2018년 9월 4일 질문

1개의 답변

0 추천

아래는 제가 만든 샘플의 일부인데요.

아래의 intent를 실행하면서 putExtra를 통해서 추가 정보를 넣고,

MainActivity에서 해당 Extra가 없으면 그냥 실행한 것이고, 있으면 노티를 터치한게 되겠죠.

 

Intent intent = new Intent(thisProtectionLocation.class);

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

intent.putExtra("NickName"nickName);

PendingIntent pendingIntent = PendingIntent.getActivity(this0 /* Request code */intent,

PendingIntent.FLAG_ONE_SHOT);

 

Uri defaultSoundUriRingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)

.setSmallIcon(R.drawable.ic_app)

.setContentTitle(messageTitle)

.setContentText(messageBody)

.setAutoCancel(true)

.setSound(defaultSoundUri)

.setContentIntent(pendingIntent);

 

NotificationManager notificationManager =

(NotificationManagergetSystemService(Context.NOTIFICATION_SERVICE);

 

notificationManager.notify(0 /* ID of notification */notificationBuilder.build());

Will Kim (43,170 포인트) 님이 2018년 9월 4일 답변
담변 감사합니다.

하지만 FirebaseMessagingService가 앱이 foreground일때는 onMessageReceived method가 불리지만

noti payload가 전달되지 않은 remoteMessage에 대해서 background일때는

onMessageReceived가 불리지 않아 intent를 전달할수가 없습니다.

이 사항은 어떻게 해결 해주셨나요?
질문이 이해가 되지 않네요.

@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
    }

상기 함수는 푸쉬 메시지가 FCM으로 부터 도착하면 호출됩니다.
저 함수에서는 Notification을 보여주는 기능만 넣으면 됩니다.

onMessageReceived 가 불려지지 않으면 노티 메시지가 아예 안떠야 합니다.

백그라운드에 있을 때는 푸쉬 메시지 자체가 보이지 않는다는 말인가요?

테스트의 상황과 증상 그리고 테스트 폰 정보를 알려주세요.
...