15

Does anyone knows how to use notification icon in status bar when downloading a file? Just like when you are downloading a file in app store. The icon is like in gif.

OcuS
  • 5,320
  • 3
  • 36
  • 45
belladonna
  • 175
  • 2
  • 11

3 Answers3

33

Just use the default android resource android.R.drawable.stat_sys_download for this.

flx
  • 14,146
  • 11
  • 55
  • 70
4

Here's a fully functioning example that will show the default "system" download notification icon in the status bar.

private static void showProgressNotification(Context context, int notificationId, String title, String message)
{
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);

    mBuilder.setContentTitle(title)
    .setContentText(message)
    .setSmallIcon(android.R.drawable.stat_sys_download)
    .setTicker("")
    .setProgress(0, 0, true);

    manager.notify(notificationId, mBuilder.build());
}

And when your "download" operation is done, clear the notification:

private static void hideProgressNotification(final NotificationManager manager, final Context context, final int id)
{
    manager.cancel(id);
}
DiscDev
  • 38,652
  • 20
  • 117
  • 133
0

Take a look to Android Download Manager. It shows a notification icon indicating that there are files downloading. Android Download Manager

osayilgan
  • 5,873
  • 7
  • 47
  • 68