From 191682784a5c60913cae9af463a976f66d56f247 Mon Sep 17 00:00:00 2001 From: EudesSilva Date: Fri, 27 Jan 2017 23:18:22 -0200 Subject: [PATCH] Solved problem in android version <= 6 , not call permissions and not call methods loads. --- .../activities/AlbumSelectActivity.java | 5 +++- .../activities/HelperActivity.java | 26 ++++++++++++++----- .../activities/ImageSelectActivity.java | 5 +++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/AlbumSelectActivity.java b/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/AlbumSelectActivity.java index 7401e5b..78016ca 100644 --- a/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/AlbumSelectActivity.java +++ b/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/AlbumSelectActivity.java @@ -147,7 +147,10 @@ public void onChange(boolean selfChange, Uri uri) { }; getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, false, observer); - checkPermission(); + // EudesSilva: BugFix: #24 + if( !checkPermission() ){ // call direct functions in android versions <= 6 + loadAlbums(); + } } @Override diff --git a/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/HelperActivity.java b/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/HelperActivity.java index cfc65f4..4720878 100644 --- a/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/HelperActivity.java +++ b/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/HelperActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; +import android.os.Build; import android.provider.Settings; import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; @@ -24,16 +25,27 @@ public class HelperActivity extends AppCompatActivity { private final int maxLines = 4; private final String[] permissions = new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }; - protected void checkPermission() { - if (ContextCompat.checkSelfPermission(this, - Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - permissionGranted(); - - } else { - ActivityCompat.requestPermissions(this, permissions, Constants.PERMISSION_REQUEST_CODE); + protected boolean checkPermission() { + if (!isMarshmallow()) { + return false; + }else { + if (ContextCompat.checkSelfPermission(this, + Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + permissionGranted(); + + } else { + ActivityCompat.requestPermissions(this, permissions, Constants.PERMISSION_REQUEST_CODE); + } + return true; } } + // EudesSilva: BugFix: #24 + // verify if version android is 6 or hight + private boolean isMarshmallow(){ + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; + } + private void requestPermission() { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { showRequestPermissionRationale(); diff --git a/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/ImageSelectActivity.java b/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/ImageSelectActivity.java index 4f46aaf..23ac182 100644 --- a/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/ImageSelectActivity.java +++ b/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/ImageSelectActivity.java @@ -171,7 +171,10 @@ public void onChange(boolean selfChange) { }; getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, false, observer); - checkPermission(); + // EudesSilva: BugFix: #24 + if( !checkPermission() ){ // call direct functions in android versions <= 6 + loadImages(); + } } @Override