2016-05-18 6 views
0

Ich versuche, den Weg von der URI mit dieser Methode zu erhalten:FileNotFoundException:/storage/emulierten/0/Bilder/

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; 

} 

Wenn ich versuche, das Bitmap zu komprimieren:

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

I erhalten diese Fehlermeldung:

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' 
+0

Ist diese Datei vorhanden => '/ storage/emulierten/0/Pictu res/IMG_20160518_165856.jpg'? – xAqweRx

Antwort

1
//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; 

}