Actualización de la barra de progreso de la descarga en el área de notificación de AsynTask
He implementado Async Task en Service. Aquí está la inicialización de la notificación de progreso, que estoy llamando de onPreExecute
.
mProgressNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); CharSequence tickerText = "Download"; mProgressNotification = new Notification(R.drawable.ic_launcher, tickerText, System.currentTimeMillis()); context = this.getApplicationContext(); Intent mNotificationIntent = new Intent(context, ActivityClass.class); PendingIntent mPendingIntent = PendingIntent.getActivity(context, 0, mNotificationIntent, 0); //mProgressNotification.flags |= Notification.FLAG_AUTO_CANCEL; mProgressNotification.flags = mProgressNotification.flags | Notification.FLAG_ONGOING_EVENT; CharSequence title = "Downloading initializing..."; RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.noti); contentView.setImageViewResource(R.id.status_icon, R.drawable.ic_launcher); contentView.setTextViewText(R.id.status_text, title); contentView.setProgressBar(R.id.status_progress, 100, 0, false); mProgressNotification.contentView = contentView; mProgressNotification.contentIntent = mPendingIntent; mProgressNotificationManager.notify(STATUS_BAR_NOTIFICATION, mProgressNotification);
Después de que en doInBackground
, he implementado mi procedimiento de descarga, y después de que estoy actualizando el progreso de descarga,
- Tamaños de las imágenes pequeñas y grandes de la notificación de Android
- Kivy - Plyer - Android - envío de notificaciones mientras la aplicación no se está ejecutando
- Android: obtener notificaciones cuando se acumulan (escucha de notificaciones)
- Notificación No se muestra
- Cómo configurar AlarmManager recurrente para ejecutar código diario
@Override protected void onProgressUpdate(Integer... progress) { super.onProgressUpdate(progress); int mDownloadProgress = progress[0]; // Log.d(TAG,"AsyncTask : download In progress"); CharSequence title = "fileName" +": " + mDownloadProgress + "%"; mProgressNotification.contentView.setTextViewText(R.id.status_text, title); mProgressNotification.contentView.setProgressBar(R.id.status_progress, 100, mDownloadProgress, false); mProgressNotificationManager.notify(STATUS_BAR_NOTIFICATION, mProgressNotification); }
Está funcionando bien .. la actualización correctamente, pero el problema es que, la barra de notificación se ahorca. No puedo subir la barra de notificación. Quiero actualizar la barra de notificación como descargar cualquier aplicación del mercado de Google (Play).
Gracias…
- Notificación sin intención pendiente
- Icono de servicio persistente en la barra de notificaciones
- ¿Cómo hacer la intención de notificación reanudar en lugar de hacer una nueva intención?
- Notificación en tiempo específico
- ¿Cómo mostrar la notificación del servicio de fondo?
- LED de notificación - color
- Ocultar la barra de progreso del área de notificación en android cuando se completa el 100%
- Evitar una nueva instancia de actividad después de hacer clic en la notificación
Lo que parece estar sucediendo es que está reemplazando la notificación, lo que significa que hay una nueva notificación para mostrar.
Lo que debe hacer es actualizar la notificación y no reemplazarla.
Echa un vistazo a esto 🙂
http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating
- ¿Cómo se puede desinstalar una aplicación?
- No se puede establecer el ancho mínimo de la barra de búsqueda creada dinámicamente