|
|
|
|
@ -56,7 +56,7 @@ public class FileChooser { |
|
|
|
|
if (DocumentsContract.isDocumentUri(context, uri)) path = getPathFromDocumentUri(context, uri); |
|
|
|
|
else if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) path = getDataColumn(context, uri); |
|
|
|
|
else if (ContentResolver.SCHEME_FILE.equalsIgnoreCase(uri.getScheme())) path = uri.getPath(); |
|
|
|
|
return path != null ? path : createFileFromUri(context, uri).getAbsolutePath(); |
|
|
|
|
return path != null ? path : createFileFromUri(context, uri); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String getPathFromDocumentUri(Context context, Uri uri) { |
|
|
|
|
@ -100,7 +100,7 @@ public class FileChooser { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static File createFileFromUri(Context context, Uri uri) { |
|
|
|
|
private static String createFileFromUri(Context context, Uri uri) { |
|
|
|
|
String[] projection = {MediaStore.MediaColumns.DISPLAY_NAME}; |
|
|
|
|
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); |
|
|
|
|
try (cursor) { |
|
|
|
|
@ -115,7 +115,7 @@ public class FileChooser { |
|
|
|
|
while ((count = is.read(buffer)) != -1) os.write(buffer, 0, count); |
|
|
|
|
os.close(); |
|
|
|
|
is.close(); |
|
|
|
|
return file; |
|
|
|
|
return file.getAbsolutePath(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|