多线程多任务下载器(一)

一、每个文件应该要有自己独特的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);

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值