I'm adding Push Notifications via GCM to my app, but I am stuck on something.
When I send a Push Notification with my app on foreground (open and on screen), it displays normally, as intended:
But when I send it with my app on background, it displays like this:
So my large image and icon background color doesn't display.
Code for GCM HTTP Call:
{
"notification": {
"title": "Tecolutla, Veracruz",
"body": "¡Bienvenidos a Tecolutla!",
"icon": "push"
},
"priority": "high",
"data": {
"Mensaje": "Descubre muchísimos lugares en Visita Xalapa.",
"Class" : "Festividades"
},
"to": "/topics/global"
}
Code for GsmListenerService:
@SuppressWarnings("ConstantConditions")
private void sendNotification(Bundle data) {
Intent intent = new Intent(this, TecolutlaVeracruz.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("Push_Title", data.getBundle("notification").getString("title"));
intent.putExtra("Push_Body", data.getBundle("notification").getString("body"));
intent.putExtra("Push_Mensaje", data.getString("Mensaje"));
int Color = ColorManager.getColorBase(Main.INICIO);
if(data.containsKey("Class")){
if(data.getString("Class").equals("Inicio")) Color = ColorManager.getColorBase(Main.INICIO);
else if(data.getString("Class").equals("Nuestro Municipio")) Color = ColorManager.getColorBase(Main.NUESTRO_MUNICIPIO);
else if(data.getString("Class").equals("Festividades")) Color = ColorManager.getColorBase(Main.FESTIVIDADES);
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.push)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.acercade_applogo))
.setContentTitle(data.getBundle("notification").getString("title"))
.setContentText(data.getBundle("notification").getString("body"))
.setAutoCancel(true)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setColor(Color)
.setVibrate(new long[]{ 0, 100, 200, 300 })
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
Another issue I have, is that the notification won't display if the app is killed or not running. Is this normal?