Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

android - How to animate the progress notification icon

I am building the notification progress bar in Service in such a way that is given below :

private NotificationManager mNotifyManager;
private NotificationCompat.Builder mBuilder;



 mBuilder =
                    new NotificationCompat.Builder(DownloadService.this)
                            .setSmallIcon(R.drawable.download)
                            .setContentTitle("MayUp")
                            .setContentText("Downloading new tools")
                            .setTicker("Downloading in progress");
            mBuilder.setAutoCancel(true);
            Intent targetIntent = new Intent(DownloadService.this, ListClass.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(DownloadService.this);
            // Adds the back stack for the Intent (but not the Intent itself)
            stackBuilder.addParentStack(MyActivity.class);
            // Adds the Intent that starts the Activity to the top of the stack
            stackBuilder.addNextIntent(targetIntent);
//            PendingIntent contentIntent = PendingIntent.getActivity(DownloadService.this, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//            mBuilder.setContentIntent(contentIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);

            mNotifyManager.notify(1, mBuilder.build());

            mBuilder.setProgress(100, 0, false);
            mNotifyManager.notify(1, mBuilder.build());

its working fine , the notification and the progress bar is showing all fine , I wanted the simple progress bar in the notification and it is the simple and I have no problem with that but what I want is given below :

What I want:

I want that My notification Icon should animate like the google play store app does, it animates its icon to show that download in progress. I want to do the same. Please tell me by using builder and notification manager How can I get this , I have seen many tutorial but they are deprecated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

By using this code you can display a notification for downloading some files with a animated icon:

mBuilder.setContentTitle("Downloading... ")
        .setContentText("Please wait...")
        .setOngoing(true)
        .setOnlyAlertOnce(true)
        .setSmallIcon(android.R.drawable.stat_sys_download)  // here is the animated icon
        .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), android.R.drawable.stat_sys_download)).build();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...