Search code examples
androidnotificationsandroid-4.2-jelly-beanandroid-2.3-gingerbread

Android notifications: compatibility with APIs


I'm trying to show notifications in my app along with a progress bar in it.

My app specs are that I'm targeting API 15 with minimum SDK set to 8. I'm using the following code to show notifications:

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

mBuilder.setContentTitle("My Application")
        .setContentText("Downloading...")
        .setProgress(0, 0, true)
        .setSmallIcon(R.drawable.ic_launcher);

PendingIntent in = PendingIntent.getActivity(getApplicationContext(), 0, getIntent(), 0);
mBuilder.setContentIntent(in);

mNotificationManager.notify(0, mBuilder.build());

With the above code the notifications appear in the notification drawer but no progress bar (on Android 2.2, and 2.3.3). But the progress bar appears fine on Android 4.1. So its obvious that its a compatibility issue.

How do I code that my notification with an indefinite progress bar appear on the APIs that I'm targeting. I tried using Notification.Builder but this class is not available on my current specs.

Thanks in advance!

-Faraz Azhar


Solution

  • Have you tried using http://developer.android.com/reference/android/widget/RemoteViews.html ?