Fix su folder di download degli aggiornamenti
This commit is contained in:
parent
299e066436
commit
062f877777
@ -48,7 +48,7 @@ public class UpdatesManager {
|
||||
|
||||
private void installAPK(String downloadURL) {
|
||||
|
||||
String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
|
||||
File destination = mContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
|
||||
|
||||
var progressDialogBuilder = new DialogProgressView("Download", null, false);
|
||||
progressDialogBuilder.show(mContext.getSupportFragmentManager(), "tag");
|
||||
@ -74,10 +74,10 @@ public class UpdatesManager {
|
||||
intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
|
||||
fileLoc = GenericFileProvider.getUriForFile(mContext,
|
||||
mContext.getApplicationContext().getPackageName() + ".core.update.GenericFileProvider",
|
||||
new File(destPath));
|
||||
destPath);
|
||||
} else {
|
||||
intent = new Intent(Intent.ACTION_VIEW);
|
||||
fileLoc = Uri.fromFile(new File(destPath));
|
||||
fileLoc = Uri.fromFile(destPath);
|
||||
}
|
||||
|
||||
intent.setDataAndType(fileLoc, "application/vnd.android.package-archive");
|
||||
|
||||
@ -15,23 +15,20 @@ import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
public class FileDownloader {
|
||||
|
||||
private String urlString;
|
||||
private String destFolder;
|
||||
private File destFolder;
|
||||
|
||||
private RunnableArgs<Integer> onProgressUpdate;
|
||||
private RunnableArgs<String> onDownloadCompleted;
|
||||
private RunnableArgs<File> onDownloadCompleted;
|
||||
|
||||
|
||||
public void download() throws Exception {
|
||||
InputStream input = null;
|
||||
OutputStream output = null;
|
||||
HttpURLConnection connection = null;
|
||||
String destPathFile;
|
||||
File downloadFile = null;
|
||||
|
||||
try {
|
||||
File direct = new File(destFolder);
|
||||
if (!direct.exists()) {
|
||||
direct.mkdirs();
|
||||
}
|
||||
if (!destFolder.exists()) destFolder.mkdirs();
|
||||
|
||||
URL url = new URL(urlString);
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
@ -46,13 +43,12 @@ public class FileDownloader {
|
||||
int downloadedBytes = 0;
|
||||
|
||||
String title = URLUtil.guessFileName(String.valueOf(url), null, null);
|
||||
downloadFile = new File(destFolder, title);
|
||||
|
||||
destPathFile = destFolder + title;
|
||||
if (downloadFile.exists())
|
||||
downloadFile.delete();
|
||||
|
||||
if (new File(destPathFile).exists())
|
||||
new File(destPathFile).delete();
|
||||
|
||||
output = new FileOutputStream(destPathFile);
|
||||
output = new FileOutputStream(downloadFile);
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
@ -79,7 +75,7 @@ public class FileDownloader {
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
if (onDownloadCompleted != null) onDownloadCompleted.run(destPathFile);
|
||||
if (onDownloadCompleted != null) onDownloadCompleted.run(downloadFile);
|
||||
}
|
||||
|
||||
|
||||
@ -92,11 +88,11 @@ public class FileDownloader {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDestFolder() {
|
||||
public File getDestFolder() {
|
||||
return destFolder;
|
||||
}
|
||||
|
||||
public FileDownloader setDestFolder(String destFolder) {
|
||||
public FileDownloader setDestFolder(File destFolder) {
|
||||
this.destFolder = destFolder;
|
||||
return this;
|
||||
}
|
||||
@ -106,7 +102,7 @@ public class FileDownloader {
|
||||
return this;
|
||||
}
|
||||
|
||||
public FileDownloader setOnDownloadCompleted(RunnableArgs<String> onDownloadCompleted) {
|
||||
public FileDownloader setOnDownloadCompleted(RunnableArgs<File> onDownloadCompleted) {
|
||||
this.onDownloadCompleted = onDownloadCompleted;
|
||||
return this;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user