android - 如何动画进度通知图标

标签 android android-notifications android-progressbar android-notification-bar

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

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());

它工作正常,通知和进度条显示一切正常,我想要通知中的简单进度条,它很简单,我对此没有问题,但我想要的如下:

我想要的:

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.

最佳答案

通过使用此代码,您可以使用动画图标显示下载某些文件的通知:

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();

关于android - 如何动画进度通知图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34037962/

相关文章:

android - Google Maps Android 如何显示指示边界外附近标记的箭头?

java - 如何在 Android 上预分配最大堆空间

Java将Json字符串转为数组

android - 前台服务启动一次并在点击时显示 Activity

android - 静态水平进度条android

java - 有api调用时如何在不重复代码的情况下膨胀progressBar布局

android - 异常膨胀导航图

android - 如何在一年中的特定日期创建提醒通知?

xamarin - 在 Xamarin Forms Android 中处理通知

android - 滚动 ProgressBars 的 ListView