diff --git a/tedimagepicker/src/main/AndroidManifest.xml b/tedimagepicker/src/main/AndroidManifest.xml index 812e786..6032090 100644 --- a/tedimagepicker/src/main/AndroidManifest.xml +++ b/tedimagepicker/src/main/AndroidManifest.xml @@ -1,7 +1,11 @@ - + diff --git a/tedimagepicker/src/main/java/gun0912/tedimagepicker/builder/TedImagePickerBaseBuilder.kt b/tedimagepicker/src/main/java/gun0912/tedimagepicker/builder/TedImagePickerBaseBuilder.kt index 8ecddad..4159534 100644 --- a/tedimagepicker/src/main/java/gun0912/tedimagepicker/builder/TedImagePickerBaseBuilder.kt +++ b/tedimagepicker/src/main/java/gun0912/tedimagepicker/builder/TedImagePickerBaseBuilder.kt @@ -7,11 +7,13 @@ import android.content.Context import android.content.Intent import android.content.pm.ActivityInfo import android.net.Uri +import android.os.Build import android.os.Parcelable import androidx.annotation.AnimRes import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.annotation.StringRes +import com.gun0912.tedpermission.TedPermissionResult import com.gun0912.tedpermission.rx2.TedPermission import com.tedpark.tedonactivityresult.rx2.TedRxOnActivityResult import gun0912.tedimagepicker.R @@ -25,6 +27,7 @@ import gun0912.tedimagepicker.builder.type.ButtonGravity import gun0912.tedimagepicker.builder.type.MediaType import gun0912.tedimagepicker.builder.type.SelectType import gun0912.tedimagepicker.util.ToastUtil +import io.reactivex.Single import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize @@ -102,9 +105,19 @@ open class TedImagePickerBaseBuilder>( }, { throwable -> onErrorListener?.onError(throwable) }) } - private fun checkPermission(context: Context) = TedPermission.create() - .setPermissions(Manifest.permission.READ_EXTERNAL_STORAGE) - .request() + private fun checkPermission(context: Context): Single { + val permissions = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + arrayOf( + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE, + ) + } else { + arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE) + } + return TedPermission.create() + .setPermissions(*permissions) + .request() + } private fun startActivity(context: Context) { TedImagePickerActivity.getIntent(context, this) diff --git a/tedimagepicker/src/main/java/gun0912/tedimagepicker/util/GalleryUtil.kt b/tedimagepicker/src/main/java/gun0912/tedimagepicker/util/GalleryUtil.kt index d4093d5..c54d2ad 100644 --- a/tedimagepicker/src/main/java/gun0912/tedimagepicker/util/GalleryUtil.kt +++ b/tedimagepicker/src/main/java/gun0912/tedimagepicker/util/GalleryUtil.kt @@ -40,9 +40,18 @@ internal class GalleryUtil { } val sortOrder = "$INDEX_DATE_ADDED DESC" - val projection = - arrayOf(INDEX_MEDIA_ID, INDEX_MEDIA_URI, albumName, INDEX_DATE_ADDED) - val selection = MediaStore.Images.Media.SIZE + " > 0" + + val projection = arrayOf( + INDEX_MEDIA_ID, + INDEX_MEDIA_URI, + albumName, + INDEX_DATE_ADDED + ) + val selection = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + MediaStore.Images.Media.SIZE + " > 0" + } else { + null + } val cursor = context.contentResolver.query(uri, projection, selection, null, sortOrder) val albumList: List = cursor?.let {