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