我收到此找不到的味精语音(没有这样的文件或目录) [英] I am getting this msg speech that did not find (No such file or directory)

查看:96
本文介绍了我收到此找不到的味精语音(没有这样的文件或目录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到的此msg语音没有找到(没有这样的文件或目录)路径正确,那可能是错误的吗?

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)

日志

   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行错误274

ReportFragmnet line error 274

val bitmap = MediaStore.Images.Media.getBitmap(context.contentResolver, Uri.parse("file://"+this.imageUri!!)) as Bitmap

路径

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-files-path

        name="files"
        path="."/>
</paths>

清单

  <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>

捕获图库图像的方法

 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

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
    }

推荐答案

如异常所示,该路径不存在!

As the exception indicates, The path does not exist!!

作为一些建议,请尽量避免与异常作斗争,即使您确定,也要遵循它们!

As a bit of advice, try not to fight with exceptions, Just follow them, even if you're pretty sure!

无论如何这次是

val authorities = activity.packageName + ".fileprovider"

值得指责,因为您已在清单中用.provider后缀定义了提供程序.

part to blame because you have defined the provider in manifest with .provider suffix.

因此更改为:

val authorities = activity.packageName + ".provider"

它应该通过更改而起作用.

It should be working by that change.

干杯!

这篇关于我收到此找不到的味精语音(没有这样的文件或目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆