'Only 70% users get firebase notification Received
I am using Latest firebase "firebase-bom:29.0.3" SDK And I am sending notification by Topic and also tried by token array in previous code
Android Code
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pendingIntent);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());
// Since android Oreo notification channel is needed. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); }
notificationManager.notify(id, notificationBuilder.build());
Php CODE
$msg = array(
'title' => $title,
'body' => $message,
'text' => $message,
'sound' => 'default',
'badge' => $badge,
'id' => $id,
'type' => $idType,
'timestamp' => time()
);
$fields = array('to' =>'/topics/global', 'notification' => $msg, 'data' => $msg);
if(!empty($fields)){
$headers = array('Authorization: key=' . env('FIREBASE_FCM_API_KEY'),'Content-Type: application/json');
#Send Reponse To FireBase Server
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
return $result;
}
else{
return 0;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|