繁体   English   中英

FileNotFoundException:/ storage / emulated / 0 / Pictures /

[英]FileNotFoundException: /storage/emulated/0/Pictures/

我尝试使用此方法从URI获取路径:

 public  String getPath(Uri uri) {

    String result;
    Cursor cursor = getContentResolver().query(uri, null, null, null, null);
    if (cursor == null) { // Source is Dropbox or other similar local file path
        result = uri.getPath();
    } else {
        cursor.moveToFirst();
        int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
        result = cursor.getString(idx);
        cursor.close();
    }
    return result;

}

当我尝试压缩位图时:

bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);

我收到此错误:

05-18 16:58:56.346 19080-19080 E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Pictures/IMG_20160518_165856.jpg: open failed: ENOENT (No such file or directory)

05-18 16:58:56.346 19080-19080/E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Pictures/IMG_20160518_165856.jpg: open failed : ENOENT (No such file or directory)

05-18 16:58:56.356 19080-19080/E/JHEAD: can't open '/storage/emulated/0/Pictures/IMG_20160518_165856.jpg'
//Change this

public  String getPath(Uri uri) {

String result;
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file path
    result = uri.getPath();
} else {
    cursor.moveToFirst();
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    result = cursor.getString(idx);
    cursor.close();
}
return result;

}

//To this and try

public  String getPath(Uri uri) {

String result;
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file path
    result = uri.getPath();
} else {
    cursor.moveToFirst();
    int idx = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
Log.e("Tag", "idx " + idx);
    result = cursor.getString(idx);
    cursor.close();
}
return result;

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM