안녕하세요
안드로이드 고수님들.
현재 php -> FCM -> android단으로 정보를 처리하고 있으며,
FCM에서 android단으로 push해줄때
O -OS : 알림음, noti 팝업창, noti 모두 정상적으로 뜸.
N -OS : [알림음, noti 팝업창] 안뜸 , noti만 정상적으로 옴.
왜 이런 현상이 나타날까요?
-php code-
function send_fcm($message, $id) {
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array (
'Authorization: key=' . GOOGLE_SERVER_KEY,
'Content-Type : application/json'
);
$fields = array ( 'data' => array("message" => $message), 'notification' => array ("body" => $message));
if(is_array($id)) {
$fields['registration_ids'] = $id;
} else {
$fields['to'] = $id;
}
$fields['priority'] = "high";
$fields = json_encode($fields);
$ch = curl_init();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
curl_exec($ch);
curl_close($ch);
return $result;
}
-android code -
private void sendNotification(String messageBody) {
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);
String channelId = getString(R.string.default_notification_channel_id);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("FCM MESSAGE")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Create channel to show notifications.
String channelName = getString(R.string.default_notification_channel_name);
NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(channel);
}
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
고수님들의 조언 부탁드립니다.
*추가로 설명을 드리면 현재 개발 중인 앱이 targetSDK는 26이며 FCM console로 메시지를 보내도
두 os에서 동일한 현상이 나타나고 있습니다..ㅜㅜ*