Search code examples
androidiconssynchronizationstatusbarnotificationmanager

How does one animate the Android sync status icon?


I simply want to start and stop the sync icon that is in the status bar. I thought it would be a simple call using NotificationManager, but I cannot find the documentation or sample Q&A on the web or SO.


Solution

  • I found my answer ...

    http://libs-for-android.googlecode.com/svn-history/r46/trunk/src/com/google/android/accounts/AbstractSyncService.java

    This shows how to set and cancel the stat_notify_sync icon.

    private void showNotification(String authority) {
        Object service = getSystemService(NOTIFICATION_SERVICE);
        NotificationManager notificationManager = (NotificationManager) service;
        int icon = android.R.drawable.stat_notify_sync;
        String tickerText = null;
        long when = 0;
        Notification notification = new Notification(icon, tickerText, when);
        Context context = this;
        CharSequence contentTitle = "mobi"; //createNotificationTitle();
        CharSequence contentText = "bob"; //createNotificationText();
        PendingIntent contentIntent = createNotificationIntent();
        notification.when = System.currentTimeMillis();
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        notificationManager.notify(mNotificationId, notification);
    }
    
    private void cancelNotification() {
        Object service = getSystemService(NOTIFICATION_SERVICE);
        NotificationManager nm = (NotificationManager) service;
        nm.cancel(mNotificationId);
    }