try ... catch in OTADownloader.java

This commit is contained in:
Erik Kiznov
2022-08-16 18:57:05 +03:00
committed by gdlbo
parent b6133da808
commit 9cbc45dea3
3 changed files with 31 additions and 8 deletions
@@ -11,6 +11,8 @@ import android.content.IntentFilter;
import android.net.Uri;
import android.os.Environment;
import com.vk.core.dialogs.alert.VkAlertDialog;
import java.io.File;
import b.h.g.m.FileUtils;
@@ -56,16 +58,31 @@ public class OTADownloader {
public static void downloadBuild(String url) {
var context = AndroidUtils.getGlobalContext();
var uri = Uri.parse(url);
try {
var uri = Uri.parse(url);
context.registerReceiver(callback, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
context.registerReceiver(callback, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
var request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setTitle("VTLite.apk");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "VTLite.apk");
var request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setTitle("VTLite.apk");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "VTLite.apk");
var manager = (DownloadManager) AndroidUtils.getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
var manager = (DownloadManager) AndroidUtils.getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
} catch (Exception e) {
e.printStackTrace();
VkAlertDialog.Builder alertDialog = new VkAlertDialog.Builder(context);
alertDialog.setTitle(AndroidUtils.getString("update_error"));
alertDialog.setMessage(AndroidUtils.getString("update_error_text"));
alertDialog.setPositiveButton(AndroidUtils.getString("no"), (dialog, which) -> {
dialog.cancel();
});
alertDialog.setNeutralButton(AndroidUtils.getString("yes"), (dialog, which) -> {
context.startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse("https://github.com/vtosters/lite/releases/latest/")));
});
var alert = alertDialog.create();
alert.show();
}
}
}
+3
View File
@@ -6159,4 +6159,7 @@
<string name="encryption_public_algorithm_error">Выбранный алгоритм публичный и не имеет настроек!</string>
<string name="encryption_enter_key">Введите ключ шифрования</string>
<string name="encryption_current_algorithm_title">Используемый алгоритм: %1$s.\nУчтите, что если поле будет пустым, то будет использоваться ключ по умолчанию.</string>
<string name="update_error">Ошибка обновления</string>
<string name="update_error_text">Произошла ошибка при попытке скачать новую версию приложения.\nОбновить приложение вручную?</string>
</resources>
+3
View File
@@ -6297,4 +6297,7 @@ May look like a fake leaving the online"</string>
<string name="encryption_public_algorithm_error">The selected algorithm is public and has no settings!</string>
<string name="encryption_enter_key">Enter encryption key</string>
<string name="encryption_current_algorithm_title">Algorithm used: %1$s.\nPlease note that if the field is empty, the default key will be used.</string>
<string name="update_error">Update failed</string>
<string name="update_error_text">An error occurred while trying to download the new version of the app.\nDo you want to update the app manually?</string>
</resources>