Skip to content

Commit

Permalink
Update WRITE_EXTERNAL_STORAGE usage for newer APIs on advertiseImageO…
Browse files Browse the repository at this point in the history
…ptimization
  • Loading branch information
irfano committed Mar 27, 2023
1 parent 324c4c0 commit bb26d70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
Expand Down Expand Up @@ -987,14 +988,14 @@ private void updateImageSizeParameters() {
* saves the media to the local device using the Android DownloadManager
*/
private void saveMediaToDevice() {
// must request permissions even though they're already defined in the manifest
String[] permissionList = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
if (!PermissionUtils.checkAndRequestPermissions(this, WPPermissionUtils.MEDIA_PREVIEW_PERMISSION_REQUEST_CODE,
permissionList)) {
return;
// must request the permission even though it's already defined in the manifest
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
String[] permissionList = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
if (!PermissionUtils.checkAndRequestPermissions(this,
WPPermissionUtils.MEDIA_PREVIEW_PERMISSION_REQUEST_CODE,
permissionList)) {
return;
}
}

if (!NetworkUtils.checkConnection(this)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.pm.PackageManager;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.ViewConfiguration;
Expand Down Expand Up @@ -121,8 +122,9 @@ public static boolean shouldAdvertiseImageOptimization(final Context context) {
}

// Check we can access storage before asking for optimizing image
boolean hasStoreAccess = ContextCompat.checkSelfPermission(
context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
boolean hasStoreAccess = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
|| ContextCompat.checkSelfPermission(context,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
if (!hasStoreAccess) {
return false;
}
Expand Down

0 comments on commit bb26d70

Please sign in to comment.