ExifInterface没有使用给定的filePath初始化

时间:2018-02-24 17:37:34

标签: java android exif

所以我试图从我的手机本地图库中的图像中获取Exif数据,但由于某种原因ExifInterface没有初始化。我正在将文件路径打印到日志中,看起来很好,示例文件路径为 /storage/emulated/0/DCIM/Camera/IMG_20170429_234417.jpg

我提供了错误的文件路径吗?

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == LOAD_IMAGE_RESULTS && resultCode == RESULT_OK && data != null) {
        Uri pickedImage = data.getData();
        String[] filePath = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
        cursor.moveToFirst();
        String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));

        ExifInterface exifInterface = null;
        InputStream in = null;
        try {
             exifInterface = new ExifInterface(imagePath);
        } catch (IOException e) {
            Log.i("homeActivity": "Failed exifInterface Initialise");
        }
        cursor.close();
    }
}

错误日志如下

java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/IMG_20171219_122829.jpg (Permission denied)
                                                                             at java.io.FileInputStream.open0(Native Method)
                                                                             at java.io.FileInputStream.open(FileInputStream.java:200)
                                                                             at java.io.FileInputStream.<init>(FileInputStream.java:150)
                                                                             at java.io.FileInputStream.<init>(FileInputStream.java:103)
                                                                             at android.media.ExifInterface.<init>(ExifInterface.java:1331)
                                                                             at com.trinity.ebusiness.photo2nav.HomeActivity.onActivityResult(HomeActivity.java:49)
                                                                             at android.app.Activity.dispatchActivityResult(Activity.java:7267)
                                                                             at android.app.ActivityThread.deliverResults(ActivityThread.java:4524)
                                                                             at android.app.ActivityThread.handleSendResult(ActivityThread.java:4571)
                                                                             at android.app.ActivityThread.-wrap19(Unknown Source:0)
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                             at android.os.Looper.loop(Looper.java:164)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:6809)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

如果有帮助,我在清单中有READ_EXTERNAL_STORAGE权限

0 个答案:

没有答案