Search code examples
androidnotificationsfragmentation

Android : Notification not working on 2.3.6 (Samsung galaxy y)


The following code has been confirmed to work fine on devices running HONEYCOMB+. However on Samsung galaxy Y it is not producing any notifications.

        String tickerText = userString + " Download Queued";
        Notification notification =  new NotificationCompat.Builder(this).setAutoCancel(true)
                                                .setContentTitle(userString)
                                                .setContentText("Queued")
                                                .setSmallIcon(R.drawable.stat_sys_download_done)
                                                .setWhen(System.currentTimeMillis())
                                                .setTicker(tickerText)
                                                .build();
        if(DBG_ENABLE) {
            LogUtils.logD(TAG_LOG, "Posting queue notification : " + 0);
        }
        NotificationManager notificationManager =
                (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);

Note :

  • I see the "Posting Queue notification" in the logs.
  • I have copied the drawable stat_sys_download_done from android sdk into my project.

I'm not able to think of a way to debug this problem. I'm not sure if there is anything I'm missing. Any suggestions to fix this is appreciated.


Solution

  • As CommonsWare suggested, I ran the app on a 2.3 emulator and it crashed. Reason being ContentIntent was not set. GingerBread expects a ContentIntent. So I added a dummy pending intent like :

                PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
                Notification notification =  new NotificationCompat.Builder(this).setAutoCancel(true)
                                                .setContentTitle(userString)
                                                .setContentText("Queued")
                                                .setContentIntent(pi)
                                                .setSmallIcon(R.drawable.stat_sys_download_done)
                                                .setWhen(System.currentTimeMillis())
                                                .setTicker(tickerText)
                                                .build();