# HG changeset patch # User David Barts # Date 1616563834 25200 # Node ID 0dbd924cb5e8bba1a0375fa4a9fc11b5992064c3 # Parent 70f1d11d53ad2fd9ecb0d76c450804a54e72a6d0 Explain why permission needed, per guidelines. diff -r 70f1d11d53ad -r 0dbd924cb5e8 app/src/main/java/com/bartsent/simpleresizer/EditImage.kt --- a/app/src/main/java/com/bartsent/simpleresizer/EditImage.kt Fri Mar 19 12:49:13 2021 -0700 +++ b/app/src/main/java/com/bartsent/simpleresizer/EditImage.kt Tue Mar 23 22:30:34 2021 -0700 @@ -325,12 +325,26 @@ } } + fun requestWritePermission(): Unit { + requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), REQUEST_WRITE_EXTERNAL) + } + fun doneClicked(view: View?): Unit { - // If we need a permission, request it and bail. We will be called again + // If we need WRITE_EXTERNAL_STORAGE, request it and bail. We will be called again // (with the permission) if it is granted. if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.Q) { if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { - requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), REQUEST_WRITE_EXTERNAL) + if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) + AlertDialog.Builder(this).also { + it.setMessage(getString(R.string.permission_needed, getString(R.string.app_name))) + it.setNeutralButton(R.string.ok_text) { dialog, _ -> + dialog.dismiss() + requestWritePermission() + } + it.create() + }.show() + else + requestWritePermission() return } } diff -r 70f1d11d53ad -r 0dbd924cb5e8 app/src/main/res/values/strings.xml --- a/app/src/main/res/values/strings.xml Fri Mar 19 12:49:13 2021 -0700 +++ b/app/src/main/res/values/strings.xml Tue Mar 23 22:30:34 2021 -0700 @@ -1,5 +1,8 @@ + Simple Resizer + + Invalid maximum dimension. Cancel max. dimension @@ -16,6 +19,7 @@ Unexpected %s. %d ✕ %d OK + %s needs the WRITE_EXTERNAL_STORAGE permission to save the resized image. Please approve granting this permission in the next dialog. 180˚ 90˚ CCW 90˚ CW