Skip to content

Commit

Permalink
webview默认下载器实现
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Oct 9, 2022
1 parent 1c307f5 commit d24ff72
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion baseWebview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies {
api 'com.github.hss01248:UI:0.0.1'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
api group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'

implementation "com.github.hss01248.HttpUtil2:openuri:3.1.2"
//api 'org.jsoup:jsoup:1.11.2'
api 'com.blankj:utilcodex:1.30.6'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.hss01248.basewebview;

import android.app.DownloadManager;
import android.content.Context;
import android.net.Uri;

import com.blankj.utilcode.util.Utils;
import com.hss01248.openuri.OpenUri;

import java.io.File;

/**
* @Despciption todo
* @Author hss
* @Date 09/10/2022 12:21
* @Version 1.0
*/
public class DefaultWebConfig implements WebviewInit{
@Override
public Class html5ActivityClass() {
return BaseWebviewActivity.class;
}

@Override
public IDownloader getIDownloader() {
return new IDownloader() {
@Override
public void doDownload(String url, String name, String dir) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
//设置在什么网络情况下进行下载
//request.setAllowedNetworkTypes(Request.NETWORK_WIFI);
//设置通知栏标题
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setTitle(name);
request.setDescription("正在下载");
request.setAllowedOverRoaming(false);
//设置文件存放目录
request.setDestinationUri(OpenUri.fromFile(Utils.getApp(),new File(dir)));
DownloadManager downManager = (DownloadManager)Utils.getApp().getSystemService(Context.DOWNLOAD_SERVICE);
long id= downManager.enqueue(request);

//request.setDestinationInExternalFilesDir(this, Environment.DIRECTORY_DOWNLOADS, "mydown");

}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static WebviewInit getInit() {
return init;
}

static WebviewInit init;
static WebviewInit init = new DefaultWebConfig();

public static void init(WebviewInit init){
WebConfigger.init = init;
Expand Down

0 comments on commit d24ff72

Please sign in to comment.