Fix su folder di download degli aggiornamenti

This commit is contained in:
Giuseppe Scorrano 2024-03-07 10:16:37 +01:00
parent 299e066436
commit 062f877777
2 changed files with 15 additions and 19 deletions

View File

@ -48,7 +48,7 @@ public class UpdatesManager {
private void installAPK(String downloadURL) { 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); var progressDialogBuilder = new DialogProgressView("Download", null, false);
progressDialogBuilder.show(mContext.getSupportFragmentManager(), "tag"); progressDialogBuilder.show(mContext.getSupportFragmentManager(), "tag");
@ -74,10 +74,10 @@ public class UpdatesManager {
intent = new Intent(Intent.ACTION_INSTALL_PACKAGE); intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
fileLoc = GenericFileProvider.getUriForFile(mContext, fileLoc = GenericFileProvider.getUriForFile(mContext,
mContext.getApplicationContext().getPackageName() + ".core.update.GenericFileProvider", mContext.getApplicationContext().getPackageName() + ".core.update.GenericFileProvider",
new File(destPath)); destPath);
} else { } else {
intent = new Intent(Intent.ACTION_VIEW); intent = new Intent(Intent.ACTION_VIEW);
fileLoc = Uri.fromFile(new File(destPath)); fileLoc = Uri.fromFile(destPath);
} }
intent.setDataAndType(fileLoc, "application/vnd.android.package-archive"); intent.setDataAndType(fileLoc, "application/vnd.android.package-archive");

View File

@ -15,23 +15,20 @@ import it.integry.integrywmsnative.core.expansion.RunnableArgs;
public class FileDownloader { public class FileDownloader {
private String urlString; private String urlString;
private String destFolder; private File destFolder;
private RunnableArgs<Integer> onProgressUpdate; private RunnableArgs<Integer> onProgressUpdate;
private RunnableArgs<String> onDownloadCompleted; private RunnableArgs<File> onDownloadCompleted;
public void download() throws Exception { public void download() throws Exception {
InputStream input = null; InputStream input = null;
OutputStream output = null; OutputStream output = null;
HttpURLConnection connection = null; HttpURLConnection connection = null;
String destPathFile; File downloadFile = null;
try { try {
File direct = new File(destFolder); if (!destFolder.exists()) destFolder.mkdirs();
if (!direct.exists()) {
direct.mkdirs();
}
URL url = new URL(urlString); URL url = new URL(urlString);
connection = (HttpURLConnection) url.openConnection(); connection = (HttpURLConnection) url.openConnection();
@ -46,13 +43,12 @@ public class FileDownloader {
int downloadedBytes = 0; int downloadedBytes = 0;
String title = URLUtil.guessFileName(String.valueOf(url), null, null); 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()) output = new FileOutputStream(downloadFile);
new File(destPathFile).delete();
output = new FileOutputStream(destPathFile);
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int len; int len;
@ -79,7 +75,7 @@ public class FileDownloader {
connection.disconnect(); connection.disconnect();
} }
if (onDownloadCompleted != null) onDownloadCompleted.run(destPathFile); if (onDownloadCompleted != null) onDownloadCompleted.run(downloadFile);
} }
@ -92,11 +88,11 @@ public class FileDownloader {
return this; return this;
} }
public String getDestFolder() { public File getDestFolder() {
return destFolder; return destFolder;
} }
public FileDownloader setDestFolder(String destFolder) { public FileDownloader setDestFolder(File destFolder) {
this.destFolder = destFolder; this.destFolder = destFolder;
return this; return this;
} }
@ -106,7 +102,7 @@ public class FileDownloader {
return this; return this;
} }
public FileDownloader setOnDownloadCompleted(RunnableArgs<String> onDownloadCompleted) { public FileDownloader setOnDownloadCompleted(RunnableArgs<File> onDownloadCompleted) {
this.onDownloadCompleted = onDownloadCompleted; this.onDownloadCompleted = onDownloadCompleted;
return this; return this;
} }