安卓源码进度条通知,异步任务下载,缓存Sd卡实例代码
//3.设置通知 三要素 标题、小图标、内容
builder.setContentTitle("下载中...")
.setSmallIcon(R.mipmap.ic_launcher);
//开启异步任务
new ImgAsync(new ImgAsync.CallBack() {
@Override
public void getProgress(int progress) {
builder.setContentText("下载了" + progress + "%");
builder.setProgress(100, progress, false);
if (progress == 100) {
builder.setContentTitle("点击查看")
.setContentText("下载完成");
//点击通知 跳转 封装跳转意图 PendingIntent.FLAG_ONE_SHOT有效点击次数一次
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
PendingIntent pendingIntent =
PendingIntent.getActivity(MainActivity.this, 100, intent, PendingIntent.FLAG_ONE_SHOT);
builder.setContentIntent(pendingIntent);
}
//发送通知
manager.notify(100, builder.build());
}
}).execute(path);
资源均来自第三方,谨慎下载,前往第三方网站下载