Async Task を Service に実装しました。これは、から呼び出している進行状況通知の初期化です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) から任意のアプリケーションをダウンロードするように、通知バーを更新したい。
ありがとう...