From cf99f328e9ad5f516733bc8c5054f1c394a36474 Mon Sep 17 00:00:00 2001 From: AbdurazaaqMohammed <56937889+AbdurazaaqMohammed@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:44:41 -0400 Subject: [PATCH] Update MainActivity.java Only check and request permission when downloading file --- .../com/google/android/youtube/pro/MainActivity.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/google/android/youtube/pro/MainActivity.java b/app/src/main/java/com/google/android/youtube/pro/MainActivity.java index c0d64f2..ae203b9 100644 --- a/app/src/main/java/com/google/android/youtube/pro/MainActivity.java +++ b/app/src/main/java/com/google/android/youtube/pro/MainActivity.java @@ -39,11 +39,7 @@ protected void onCreate(Bundle savedInstanceState) { } public void load(boolean dl) { dL=dl; - if (Build.VERSION.SDK_INT > 22 && Build.VERSION.SDK_INT < 28 && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { - Toast.makeText(getApplicationContext(), getString(R.string.grant_storage), Toast.LENGTH_SHORT).show(); - requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); - } - + web = findViewById(R.id.web); web.getSettings().setJavaScriptEnabled(true); web.getSettings().setSupportZoom(true); @@ -198,6 +194,11 @@ public void onPermissionRequest(final PermissionRequest request) { } private void downloadFile(String filename, String url, String mtype) { + + if (Build.VERSION.SDK_INT > 22 && Build.VERSION.SDK_INT < 28 && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { + runOnUiThread(() -> Toast.makeText(getApplicationContext(), R.string.grant_storage, Toast.LENGTH_SHORT).show()); + requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); + } try { try { String encodedFileName = URLEncoder.encode(filename, "UTF-8").replaceAll("\\+", "%20");