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

fcm으로 head-up notification이 앱이 실행중이지 않으면 작동을 안합니다.

0 추천

안녕하세요. 

fcm 알림이 오면 system tray에 알림리스트에도 나오고 head-up notification도 화면에 나오게 

아래 코드 처럼 구성했습니다.

그런데, 앱이 실행중이면 head-up notification이 잘 나오는데 앱이 실행중이 아니거나 백그라운드로 가면

head-up notification이 fcm알림이 도착해도 화면에 띄워지지 않습니다. 왜 그럴까요?

 

 

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Map<String, String> data = remoteMessage.getData();
        sendNotification(remoteMessage);
    }

    private void sendNotification(RemoteMessage message) {
        
        Intent push = new Intent(this, SplashActivity.class);
        push.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0, push, PendingIntent.FLAG_CANCEL_CURRENT);
        NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setWhen(System.currentTimeMillis())
                .setContentTitle("test")
                .setContentText(message.getNotification().getBody())
                .setCategory(NotificationCompat.CATEGORY_MESSAGE)
                .setVibrate(new long[] {0})
                .setAutoCancel(true)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setContentIntent(fullScreenPendingIntent);
        NotificationManager nm =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.notify(1, builder.build());

    }

    
}
전투안드 (210 포인트) 님이 2017년 2월 28일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...