4
我已將異步任務轉化爲服務。這是進度通知的初始化,我從onPreExecute
撥打電話。從AsynTask更新下載進度條到通知區域
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);
}
它工作正常..更新正確的,但問題是,通知酒吧被絞死。我無法上傳通知欄。我想更新通知欄,例如從谷歌市場下載任何應用程序(播放)。
謝謝...