I am trying to create File
from Uri comes from an android gallery so that I can upload it to the server.
File file = FileUtils.getFile(getContext(), image_uri);
But depending on image URI, it works or it doesn't work.(file return null)
This works.
content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F104/ORIGINAL/NONE/1326719792
This doesn't
content://com.google.android.apps.photos.contentprovider/0/1/mediakey%3A%2Flocal%253A38c415af-815a-4043-b3b3-29c7afb76439/ORIGINAL/NONE/2063753810
Only diffrence between two is first one is photo that was taken by device, the other is photo from GOOGLE CLOUD photo that automatically downloaded to gallery.
Is anyone have heard of this wierd behavior?
EDIT
FileUtils.getFile
public static File getFile(Context context, Uri uri) {
if (uri != null) {
String path = getPath(context, uri);
if (path != null && isLocal(path)) {
return new File(path);
}
}
return null;
}
public static boolean isLocal(String url) {
if (url != null && !url.startsWith("http://") && !url.startsWith("https://")) {
return true;
}
return false;
}