一、每个文件应该要有自己独特的id,怎么解决id的问题?
方法:1.考虑使用url+保存路径+文件名的字符串进行MD5运算,来作为一个任务的ID。
2.用id自增实现吧
(顺带一提,若是要使多个activity共享数据,可以使用Application context)
二、取名的问题
1.名字应该不同,可以通过subString()方法截取两个字符之间的字符串作为名字(name)。
如果字符串相同,用split()方法。
2.考虑将来引入文件打开功能,这里名字获取的
三、通知
1.原先的建造者模式已经不被推荐使用,现在创建notification的方法是:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle(textTitle)
.setContentText(textContent)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_DEFAULT);
notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
assert notificationManager != null;
notificationManager.createNotificationChannel(channel);
Notification.Builder builder = new Notification.Builder(this, "id");
Notification notification = builder.setContentTitle("the progress").build();
notificationManager.notify(1, notification);
2.给通知用进度条的数据
定义一个类,然后调用接口,就可以在activity和services中都接受数据。
3.通知设置进度条:
builder.setProgress(100, progress, false);