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

fcm푸시 sdk 28 포그라운드로 보내기

0 추천

서버단에서 밑에 형식으로 notification, data 두개를 한번에 보냅니다..

sdk 24버전에서는 백그라운드 포그라운드 이상없이 도착을합니다.

하지만 sdk28버전에서는 백그라운드만 오고 포그라운드는 오지 않네요

알림 채널 설정이랑 관련있는 오류인가요??

해결을 못하겠습니다...

 

 

    JsonObject json = new JsonObject();
    JsonObject notification = new JsonObject();
    JsonObject data = new JsonObject();
    
    //JsonObject dataJson = new JsonObject();
    // 알림 부분
    
    //디바이스전송 (앱단에서 생성된 토큰키)
    json.addProperty("to", fcmToken); 
    json.add("notification", notification);
    json.add("data", data);
    
    //앱 백그라운드 발송시 기본는 이 내용을 참조한다
    notification.addProperty("title", company);
    notification.addProperty("body", "No."+"11"+" 백그라운드 "+error); // Notification body
    notification.addProperty("icon", "ic_maroo");
    notification.addProperty("sound", "default");
    //앱 포그라운드 발송
    data.addProperty("title", company);
    data.addProperty("message", "포그라운드 "+error);
    data.addProperty("icon", "ic_maroo");

 

 

 

public class MyFirebaseMessagingService extends FirebaseMessagingService {


    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

        sendNotification(remoteMessage.getData().get("message"), remoteMessage.getData().get("title"));
        Log.d("SDK25", "데이타");

    }


    private void sendNotification(String messageBody, String title) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_maroo)
                .setContentTitle(title)
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent)
                .setVibrate(new long[]{1,1000})
                .setColor(0xd81b60);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

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

}
힘찬송 (220 포인트) 님이 2019년 6월 13일 질문

2개의 답변

+1 추천
 
채택된 답변
NotificationChannel을 검색해보세요
prague (26,200 포인트) 님이 2019년 6월 13일 답변
힘찬송님이 2019년 6월 13일 채택됨
채널 설정해서 포그라운드로 푸시를 받았습니다
하지만 동일한 메시지 2번째는 띄워주지 않네요
+1 추천
얼룩얼룩 (890 포인트) 님이 2019년 6월 13일 답변
그러면 sdk 28버전은 포그라운드 백그라운드 둘다 먹지 않네요
sdk24버전은 정상 작동 합니다.
흠 data로 전달한 FCM 안드9.0 폰에서 잘 수신 되고 있는데요.. 이상하네요
아 다시해보니까 onMessageReceived로 수신되네요..
아 sdk24에서 수신되고있엇네요 sdk28은 수신못하고 있어
prague 님 답변대로 오레오(26) 이상이면
notificationManager.createNotificationChannel(NotificationChannel)  설정을 해주셔야 합니다
...