Skip to content

Commit

Permalink
Merge pull request #617 from AEFeinstein/save-image
Browse files Browse the repository at this point in the history
#608 Only check for WRITE_EXTERNAL_STORAGE on Android R or below
  • Loading branch information
AEFeinstein authored Oct 31, 2023
2 parents 23b8197 + a967f64 commit c815088
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
Expand Down Expand Up @@ -767,16 +768,20 @@ public void saveImageWithGlide(int whereTo) {
return;
}

// Check if permission is granted
if (ContextCompat.checkSelfPermission(CardViewFragment.this.mActivity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// Request the permission
ActivityCompat.requestPermissions(CardViewFragment.this.mActivity,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
FamiliarActivity.REQUEST_WRITE_EXTERNAL_STORAGE_IMAGE);
// Wait for the permission to be granted
mSaveImageWhereTo = whereTo;
return;
// Note: If your app targets Build.VERSION_CODES.R or higher, this permission has no effect.
// See https://developer.android.com/reference/android/Manifest.permission#WRITE_EXTERNAL_STORAGE
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
// Check if permission is granted
if (ContextCompat.checkSelfPermission(CardViewFragment.this.mActivity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// Request the permission
ActivityCompat.requestPermissions(CardViewFragment.this.mActivity,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
FamiliarActivity.REQUEST_WRITE_EXTERNAL_STORAGE_IMAGE);
// Wait for the permission to be granted
mSaveImageWhereTo = whereTo;
return;
}
}

// Query the MediaStore to see if an image is already saved
Expand Down

0 comments on commit c815088

Please sign in to comment.