Closed jemshit closed 6 years ago
Hi, i am getting this exception when cropping image:
cropImageView .crop(cropImageView.sourceUri) .executeAsSingle() .flatMap { val uri = getPrivatePictureUri(this, PROFILE_CROPPED_IMAGE_NAME) cropImageView.save(it).executeAsSingle(uri) } .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) .subscribeBy(onSuccess = { }, onError = { }) .addTo(compositeDisposable) ... fun getPrivatePictureUri(context: Context, imageFileName: String): Uri? { val storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) ?: return null val file = File(storageDir, imageFileName) return file.toUriWithFileProvider(context) } fun File.toUriWithFileProvider(context: Context): Uri? { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".file_provider", this) } catch (e: Exception) { e.printStackTrace() null } } else { Uri.fromFile(this) } }
Uri of both source and save file is app specific private directory("Android/data/myAppPackage/Pictures/CroppedImage.jpg"). Problem might be related to FileProvider
Here is fileProvider.xml
<paths> <!--For Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)--> <external-path name="external_path_image" path="Pictures"/> <!--For Context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)--> <external-files-path name="external_file_image" path="Pictures"/> </paths>
PS: image is cropped and saved into file, but exception is raised
I solved the problem by using Uri.fromFile(this) instead of FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".file_provider", this).
Uri.fromFile(this)
FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".file_provider", this)
Hi, i am getting this exception when cropping image:
Uri of both source and save file is app specific private directory("Android/data/myAppPackage/Pictures/CroppedImage.jpg"). Problem might be related to FileProvider
Here is fileProvider.xml
PS: image is cropped and saved into file, but exception is raised