I am getting this msg speech that did not find (No such file or directory) the path is correct what could be wrong?
W/System.err: java.io.FileNotFoundException: /map.app.fileprovider/files/Pictures/JPEG_20190507_180502_4494360846236185755.jpg (No such file or directory)
LOG
W/System.err: java.io.FileNotFoundException: /map.app.fileprovider/files/Pictures/JPEG_20190507_180502_4494360846236185755.jpg (No such file or directory)
W/System.err: at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:200)
W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:150)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
W/System.err: at android.content.ContentResolver.openInputStream(ContentResolver.java:965)
at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:888)
W/System.err: at map.app.fragments.ReportFragment.onActivityResult(ReportFragment.kt:274)
ReportFragmnet line error 274
val bitmap = MediaStore.Images.Media.getBitmap(context.contentResolver, Uri.parse("file://"+this.imageUri!!)) as Bitmap
path
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-files-path
name="files"
path="."/>
</paths>
manifest
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/paths" />
</provider>
method to capture the gallery image
fun openCamera() {
try {
val imageFile = createImageFile()
val callCameraIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if(callCameraIntent.resolveActivity(activity.packageManager) != null) {
val authorities = activity.packageName + ".fileprovider"
this.imageUri = FileProvider.getUriForFile(context, authorities, imageFile)
callCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri)
startActivityForResult(callCameraIntent, IMAGE_PICK_CODE)
}
} catch (e: IOException) {
Toast.makeText(context, "Could not create file!", Toast.LENGTH_SHORT).show()
}
}
onActivityResult
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == IMAGE_PICK_CODE && resultCode == RESULT_OK) {
try {
//Getting the Bitmap from Gallery
val bitmap = MediaStore.Images.Media.getBitmap(context.contentResolver, Uri.parse("file://"+this.imageUri!!)) as Bitmap
this.imgThumb!!.setImageBitmap(bitmap)
this.pictureTaken = true
} catch (e:IOException) {
e.printStackTrace()
}
} else {
Toast.makeText(context, "Error loading image", Toast.LENGTH_LONG)
}
}
@Throws(IOException::class)
fun createImageFile(): File {
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date())
val imageFileName: String = "JPEG_" + timeStamp + "_"
val storageDir: File = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
if(!storageDir.exists()) storageDir.mkdirs()
val imageFile = File.createTempFile(imageFileName, ".jpg", storageDir)
imageFilePath = imageFile.absolutePath
return imageFile
}