完善下载
This commit is contained in:
@ -6,11 +6,13 @@ import android.os.Environment;
|
||||
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||
import com.arialyy.downloadutil.util.Util;
|
||||
import com.arialyy.frame.util.AndroidUtils;
|
||||
import com.arialyy.frame.util.StringUtil;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseModule;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -24,14 +26,23 @@ public class DownloadModule extends BaseModule {
|
||||
|
||||
/**
|
||||
* 设置下载数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<DownloadEntity> getDownloadData() {
|
||||
List<DownloadEntity> list = DownloadEntity.findAllData(DownloadEntity.class);
|
||||
if (list == null) {
|
||||
list = createNewDownload();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<DownloadEntity> createNewDownload() {
|
||||
List<DownloadEntity> list = new ArrayList<>();
|
||||
String[] urls = getContext().getResources()
|
||||
.getStringArray(R.array.test_apk_download_url);
|
||||
for (String url : urls) {
|
||||
String fileName = StringUtil.keyToHashKey(url) + ".apk";
|
||||
String fileName = Util.keyToHashCode(url) + ".apk";
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
entity.setDownloadUrl(url);
|
||||
entity.setDownloadPath(getDownloadPath(url));
|
||||
@ -43,9 +54,10 @@ public class DownloadModule extends BaseModule {
|
||||
|
||||
/**
|
||||
* 下载广播过滤器
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public IntentFilter getDownloadFilter(){
|
||||
public IntentFilter getDownloadFilter() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addDataScheme(getContext().getPackageName());
|
||||
filter.addAction(DownloadManager.ACTION_PRE);
|
||||
@ -60,7 +72,13 @@ public class DownloadModule extends BaseModule {
|
||||
}
|
||||
|
||||
private String getDownloadPath(String url) {
|
||||
return Environment.getExternalStorageDirectory().getPath() + "/" + AndroidUtils.getAppName(
|
||||
getContext()) + "downloads/" + StringUtil.keyToHashKey(url) + ".apk";
|
||||
String path = Environment.getExternalStorageDirectory()
|
||||
.getPath() + "/" + AndroidUtils.getAppName(getContext()) + "downloads/" + StringUtil
|
||||
.keyToHashKey(url) + ".apk";
|
||||
File file = new File(path);
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user