Skip to content

Commit

Permalink
Merge pull request #22 from ChochaNaresh/Dev
Browse files Browse the repository at this point in the history
- permission bug fixed for android 13
  • Loading branch information
ChochaNaresh authored Jun 12, 2023
2 parents 322f1d2 + 669481b commit 540e5e4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal class ImageCaptureActivity : AppCompatActivity() {
.w("File Uri ::: ${imageFileUri?.toString()}")
Timber.tag(Const.LogTag.FILE_RESULT).w("filePath ::: ${imageFile?.absoluteFile}")
Timber.tag(Const.LogTag.FILE_RESULT).w("file read:: ${imageFile?.canRead()}")
setSuccessResult(imageFileUri, imageFile?.absolutePath)
setSuccessResult(imageFileUri, imageFile?.absolutePath, true)
} else {
Timber.tag(Const.LogTag.FILE_PICKER_ERROR)
.e(getString(R.string.err_capture_error, "imageCapture"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal class VideoCaptureActivity : AppCompatActivity() {
Timber.tag(Const.LogTag.FILE_RESULT)
.w("File Uri ::: ${videoFileUri?.toString()}")
Timber.tag(Const.LogTag.FILE_RESULT).w("filePath ::: ${videoFile?.absoluteFile}")
setSuccessResult(videoFileUri, videoFile?.absolutePath)
setSuccessResult(videoFileUri, videoFile?.absolutePath, true)
} else {
Timber.tag(Const.LogTag.FILE_PICKER_ERROR)
.e(getString(R.string.err_capture_error, "videoCapture"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,42 @@ internal fun Context.getSettingIntent(): Intent {
return intent
}

internal fun Activity.setSuccessResult(fileUri: Uri?, filePath: String? = null) {
internal fun Activity.setSuccessResult(
fileUri: Uri?,
filePath: String? = null,
isFromCapture: Boolean = false,
) {
setResult(
Activity.RESULT_OK,
Intent().also { mIntent ->
mIntent.flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION + Intent.FLAG_GRANT_READ_URI_PERMISSION
mIntent.flags =
if (isFromCapture) {
Intent.FLAG_GRANT_WRITE_URI_PERMISSION + Intent.FLAG_GRANT_READ_URI_PERMISSION
} else {
Intent.FLAG_GRANT_READ_URI_PERMISSION
}

fileUri?.let { mIntent.data = fileUri }
filePath?.let { mIntent.putExtra(Const.BundleExtras.FILE_PATH, it) }
},
)
finish()
}

internal fun Activity.setSuccessResult(fileUri: List<Uri>?, filePath: ArrayList<String>? = null) {
internal fun Activity.setSuccessResult(
fileUri: List<Uri>?,
filePath: ArrayList<String>? = null,
isFromCapture: Boolean = false,
) {
setResult(
Activity.RESULT_OK,
Intent().also { mIntent ->
mIntent.flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION + Intent.FLAG_GRANT_READ_URI_PERMISSION
mIntent.flags =
if (isFromCapture) {
Intent.FLAG_GRANT_WRITE_URI_PERMISSION + Intent.FLAG_GRANT_READ_URI_PERMISSION
} else {
Intent.FLAG_GRANT_READ_URI_PERMISSION
}
if (!fileUri.isNullOrEmpty()) {
val mClipData = ClipData.newUri(contentResolver, "uris", fileUri.first())
fileUri.subList(1, fileUri.size).forEach {
Expand Down

0 comments on commit 540e5e4

Please sign in to comment.