android开发中实现下载文件通知栏显示进度条。
1、使用asynctask异步任务实现,调用publishprogress()方法刷新进度来实现(已优化)
public class myasynctask extends asynctask {
private context context;
private notificationmanager notificationmanager;
private notificationcompat.builder builder;
public myasynctask(context context){
this.context = context;
notificationmanager = (notificationmanager) context.getsystemservice(activity.notification_service);
builder = new notificationcompat.builder(context);
}
@override
protected void onpreexecute() {
super.onpreexecute();
builder.setsmallicon(r.mipmap.ic_launcher)
.setcontentinfo("下载中...")
.setcontenttitle("正在下载");
}
@override
protected integer doinbackground(string... params) {
log.e(tag, "doinbackgrou