Closed anshad closed 8 years ago
@anshad Are you by any chance using Cordova/Phonegap or is your Android app native?
I am using native app and the code is copied from https://github.com/googlesamples/google-services/tree/master/android/gcm
Try adding data to the message, if I recall, GCM is bugged when sending only a notification
object without a data
object:
message.addData('test', 'test');
Tried, still not working. Found something strange in the sample code I am using,
private void sendNotification(String message) {
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);
android.support.v4.app.NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle("GCM Message")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
Looks like here the Android code manually sets something different. Help me to update this.
Thanks, the issue was with my Android parsing function. It was expecting message
in the notification context.
When I am running my code, I am getting notification on my android device (Lolipop) notification bar with title
GCM Message
and the icon. But I am not able to see the title and body provided in the push message.