diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index af063ac..77447e8 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,6 +5,7 @@
+
{
try {
Release release = new Gson().fromJson(response, Release.class);
- preferences.setLastCheckUpdate();
if (release.versionCode <= BuildConfig.VERSION_CODE) return;
@@ -173,20 +178,36 @@ private void showAlertError(String error) {
}
private void showAlertUpdate(String message, String fileUrl) {
+ if (Build.VERSION.SDK_INT >= VERSION_CODES.M
+ && ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(this,
+ new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },1000);
+ }
+
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(R.string.alert_new_update)
.setMessage(message)
.setPositiveButton(R.string.dialog_download, (dialog, id) -> downloadFile(fileUrl))
- .setNegativeButton(R.string.dialog_close, (dialog, id) -> dialog.cancel());
+ .setNegativeButton(R.string.dialog_skip, (dialog, id) -> preferences.setLastCheckUpdate());
alert.create().show();
}
private void downloadFile(String url) {
- DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
- DownloadManager manager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
- if (manager != null) {
- manager.enqueue(request);
+ DownloadManager dm = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
+ if (dm == null) return;
+
+ Uri uri = Uri.parse(url);
+ DownloadManager.Request request = new DownloadManager.Request(uri)
+ .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, uri.getLastPathSegment())
+ .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
+ .setVisibleInDownloadsUi(true);
+
+ try {
+ dm.enqueue(request);
+ }
+ catch (Exception e) {
+ Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 4a02fef..897f700 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -22,8 +22,8 @@
Pembaharuan
- Unduh
- Tutup
+ Unduh APK
+ Abaikan Sehari
Versi\n• Terpasang : %s (%d)\n• Terkini : %s (%d)\n\nPerubahan :
\n• %s
\n• lain-lain