Fix for CB-10625

getDocumentId was crashing in some cases.
Now, in case it crashes, it will use the original uri to query.
This commit is contained in:
Julio César 2016-02-21 21:00:14 +01:00 committed by Joe Bowser
parent 61b77951e1
commit 019346d188

View File

@ -79,19 +79,26 @@ public class FileHelper {
@SuppressLint("NewApi") @SuppressLint("NewApi")
public static String getRealPathFromURI_API19(Context context, Uri uri) { public static String getRealPathFromURI_API19(Context context, Uri uri) {
String filePath = ""; String filePath = "";
try {
String id = null;
Uri myUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;;
try { try {
String wholeID = DocumentsContract.getDocumentId(uri); String wholeID = DocumentsContract.getDocumentId(uri);
// Split at colon, use second item in the array // Split at colon, use second item in the array
String id = wholeID.indexOf(":") > -1 ? wholeID.split(":")[1] : wholeID.indexOf(";") > -1 ? wholeID id = wholeID.indexOf(":") > -1 ? wholeID.split(":")[1] : wholeID.indexOf(";") > -1 ? wholeID
.split(";")[1] : wholeID; .split(";")[1] : wholeID;
} catch (Exception e) {
myUri = uri;
}
String[] column = { MediaStore.Images.Media.DATA }; String[] column = { MediaStore.Images.Media.DATA };
// where id is equal to // where id is equal to
String sel = MediaStore.Images.Media._ID + "=?"; String sel = MediaStore.Images.Media._ID + "=?";
Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, column, Cursor cursor = context.getContentResolver().query(myUri, column,
sel, new String[] { id }, null); sel, new String[] { id }, null);
int columnIndex = cursor.getColumnIndex(column[0]); int columnIndex = cursor.getColumnIndex(column[0]);