更新下载进度条到从AsynTask通知区域 [英] Updating download progress bar into notification area from AsynTask

查看:98
本文介绍了更新下载进度条到从AsynTask通知区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现异步任务投入使用。下面是进度通知的初始化,那我从上preExecute

I have implemented Async Task into Service. Here is the initializing of Progress Notification, that I am calling from 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);

之后,在 doInBackground ,我已经实现了我的下载程序,在那之后我更新下载进度,

After that in doInBackground , I have implemented my download procedure, and after that I am updating download progress,

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

    }

这是工作的罚款..更新正确​​的,但问题是,通知栏被处以绞刑。我不能上下通知栏。我想更新通知栏像谷歌市场(播放)下载任何应用程序。

It is working fine.. updating properly, but issue is that, Notification bar is hanged. I can not up-down notification bar. I want to update notification bar like downloading any application from Google market (Play) .

谢谢...

推荐答案

这似乎是发生的是,要更换的通知,这意味着有新的通知显示。

What appears to be happening is that you are replacing the notification meaning that there is a new notification to show.

您需要做的就是更新通知,而不是取代它。

What you need to do is update the notification and not replace it.

有一个看看这个:)

http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating

这篇关于更新下载进度条到从AsynTask通知区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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