如何动画进度通知图标 [英] How to animate the progress notification icon

查看:20
本文介绍了如何动画进度通知图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以下面给出的方式在服务中构建通知进度条:

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 :

我想要的:

我希望我的通知图标应该像 google play 一样有动画效果商店应用程序可以,它会为其图标设置动画以显示下载进步.我也想这样做.请告诉我使用构建器和通知管理器我怎么能得到这个,我看过很多教程但它们已被弃用.

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.

推荐答案

您可以按照上面 Rushab patel 的回答中的描述制作动画列表,但是如果您使用的是最新的 api 并且您的目标是新的软件开发工具包.

you can make the animation list as described above in the answer of Rushab patel but there could be problem if you are using the newst api and if you are targetting the new sdk .

所以下面这行会过时并被弃用

so this following line would become outdated and deprecated

通知通知 = 新通知(R.drawable.wheelAnim,null, System.currentTimeMillis());

Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis());

这在编码通知方面太糟糕了,我必须建议您如上所述使用通知生成器,因此我建议您直接在通知生成器中使用此动画列表可绘制.

which is too bad in coding notification , I must suggest you as you have described above that you are using notification builder , thus I would recomend you to directly use this animation list drawable in the notification builder.

来自你的片段

mBuilder =
                    new NotificationCompat.Builder(DownloadService.this)
                            .setSmallIcon(R.drawable.youAnimationList)
                            .setContentTitle("MayUp")
                            .setContentText("Downloading new tools")
                            .setTicker("Downloading in progress");
            mBuilder.setAutoCancel(true);

这篇关于如何动画进度通知图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆