0

I am sending GCM notification using the following code :

private void sendNotification2(Bundle extras) {
    mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    Bundle bundle = new Bundle();
    bundle.putString("buzz", "buzz");
    intent.putExtras(bundle);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            intent, 0);

    String appname = extras.getString("appname");
    String contenttxt = extras.getString("alert");
    String title = extras.getString("title");
    Logger.append("Notification Intent", extras.toString());

    try {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this)
                .setSmallIcon(R.drawable.myicon)
                .setLargeIcon(
                        BitmapFactory.decodeResource(getResources(),
                                R.drawable.splash))
                .setContentTitle(title)
                .setDefaults(Notification.DEFAULT_ALL)
                .setOnlyAlertOnce(true)
                .setAutoCancel(true)
                .setStyle(
                        new NotificationCompat.BigTextStyle()
                                .bigText(title)).setContentText(contenttxt);

        mBuilder.setContentIntent(contentIntent);

        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    } catch (Exception ex) {
        Logger.append("Invalid Notificatoin msg", "");
    }
}

Here are the problems i am facing.

when I receive notification, if I click on it, on a Note 4 with Kitkat 4.4.4, the app opens well. But on LG Optimus with Kitkat 4.4.2 , the app does not open up.

any pointers on what to look for, to debug ?

techtinkerer
  • 1,280
  • 2
  • 15
  • 26

1 Answers1

0

OK, this seems to be a known Kitkat issue per other threads in Stackoverflow.

Notification Click not launch the given Activity on Nexus Phones

Adding the two flags as below solved the issue.

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
         intent, PendingIntent.FLAG_UPDATE_CURRENT  | PendingIntent.FLAG_ONE_SHOT);
Community
  • 1
  • 1
techtinkerer
  • 1,280
  • 2
  • 15
  • 26