【问题标题】:Updating download progress bar into notification area from AsynTask从 AsyncTask 将下载进度条更新到通知区域
【发布时间】:2012-06-29 04:53:30
【问题描述】:

我已将异步任务实施到服务中。这是我从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之后,我已经实现了我的下载过程,之后我正在更新下载进度,

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

    }

它工作正常.. 正确更新,但问题是,通知栏被挂起。我不能上下通知栏。我想更新通知栏,例如从 Google 市场 (Play) 下载任何应用程序。

谢谢...

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    似乎正在发生的事情是您正在替换通知,这意味着有一个新的通知要显示。

    您需要做的是更新通知而不是替换它。

    看看这个:)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 2011-12-17
      相关资源
      最近更新 更多