Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - show animated status bar icon

I'm trying to set my notification status bar icon as animated android.R.drawable.stat_sys_upload, it works fine, but the icon do not animate:

private void showStatusNotification() {

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setAutoCancel(false);
    notificationBuilder.setOngoing(true);
    notificationBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this,
            MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
    notificationBuilder.setContentTitle(getString(R.string.notification_title));
    notificationBuilder.setContentText(getString(R.string.notification_text));
    notificationBuilder.setSmallIcon(android.R.drawable.stat_sys_upload);
    notificationManager
            .notify(STATUS_NOTIFICATION_ID, notificationBuilder.build());
}
like image 865
gingo Avatar asked Mar 09 '13 13:03

gingo


2 Answers

The solution is simple, but very tricky. You just need to add

notificationBuilder.setTicker(getString(R.string.notification_ticker));

the magic happens and your icon is animated. It is related to this bug:

http://code.google.com/p/android/issues/detail?id=15657

Hope it helps someone.

like image 146
gingo Avatar answered Oct 22 '22 12:10

gingo


Just to add to @gingo's answer, in case you don't want any text to be shown in the status bar then keep your notification_ticker String as blank in strings.xml (which is quite obvious).

Also, if you want the animated icon to stop after the progress or download/ upload has completed then set a similar looking icon to your notificationBuilder and call the notify method on the notification manager as,

 mBuilder.setSmallIcon(R.drawable.ic_download);
 mNotifyManager.notify(0, mBuilder.build());
like image 21
Atul O Holic Avatar answered Oct 22 '22 13:10

Atul O Holic