【发布时间】:2018-10-05 10:52:03
【问题描述】:
<-- Android/Java --->
private NotificationManager mNotifyManager;
private NotificationCompat.Builder build;
final int id = 101;
private class Download extends AsyncTask<Void, Integer, Integer> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Displays the progress bar for the first time.
build.setProgress(100, 0, false);
mNotifyManager.notify(id, build.build());
}
@Override
protected void onProgressUpdate(Integer... values) {
// Update progress
build.setProgress(100, values[0], false);
mNotifyManager.notify(id, build.build());
super.onProgressUpdate(values);
}
@Override
protected Integer doInBackground(Void... params) {
//.........
FileOutputStream f = new FileOutputStream(new File(rootFile,
arg0[1]));
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
float conLen = c.getContentLength();
float total = 0;
while ((len1 = in.read(buffer)) > 0) {
f.write(buffer, 0, len1);
total += len1;
publishProgress((int) (total * 100 / conLen));
}
f.close();
return result;
}
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
Log.e(TAG,"in PostExecute");
build.setContentText("Download complete");
// Removes the progress bar
build.setProgress(0, 0, false);
mNotifyManager.notify(id, build.build());
}
}
}
问题
每个都认为工作正常但是当我在 postExecute 通知不更新
有人知道我哪里错了吗?
【问题讨论】:
-
这是在 android 文档中编写的用于更新通知的内容。
Caution: Android applies a rate limit when updating a notification. If you post updates to a notification too frequently (many in less than one second), the system might drop some updates.您在进度更新中多次更新通知。这可能是问题所在。 -
任何避免此问题的解决方案@VivekMishra
-
我觉得你可以从进度更新方法中删除通知
-
那么如何在通知中显示下载过程? @VivekMishra
标签: java android notifications