Send notification although the app is in foreground
I'm receiving notifications from GCM, but they are shown only if the
application is in background, or the phone is sleeping.
If the application is in foreground, I receive from GCM correctly but the
notification is not triggered and shown in notification bar.
Why is that ?
I'm using this code.
mNotificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent loadIntent = new Intent(context,
NotificationEntryPointActivity.class);
loadIntent.putExtra("op", params.getString("op"));
if (params.containsKey("params")) {
loadIntent.putExtra("params", params.getBundle("params"));
}
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
loadIntent, 0);
NotificationCompat.Builder mBuilder = new
NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(params.getString("title"))
.setContentText(params.getString("text"))
.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
.setAutoCancel(true);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(params.getInt("id"), mBuilder.build());
No comments:
Post a Comment