我正在以下面给出的方式构建服务中的通知进度条:
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());
它的做工精细,通知和进度条显示所有的罚款,我想在通知中简单的进度条,这是简单的,我有没有问题,但我想下面给出什么:
我想要的是:
我希望我的通知图标应该像谷歌游戏商店应用程序一样动画,它会激活其图标以显示正在进行的下载.我也想这样做.请通过使用构建器和通知管理器告诉我如何获得这个,我已经看过很多教程,但它们已被弃用.
Ali Sherafat.. 30
通过使用此代码,您可以显示下载带有动画图标的某些文件的通知:
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();
Rushabh Pate.. 5
使用以下代码创建.xml文件:
其中wheel0到5是车轮的图像.确保所有图像都在可绘制文件夹中.
下面的用户将代码片段放入代码中以制作动画图标:
Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this, getText(R.string.someTitle),getText(R.string.someText), pendingIntent); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(uid, notification);
参考链接
通过使用此代码,您可以显示下载带有动画图标的某些文件的通知:
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();
使用以下代码创建.xml文件:
其中wheel0到5是车轮的图像.确保所有图像都在可绘制文件夹中.
下面的用户将代码片段放入代码中以制作动画图标:
Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this, getText(R.string.someTitle),getText(R.string.someText), pendingIntent); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(uid, notification);
参考链接