catch rare exception when transforming download uri to real path

This commit is contained in:
Daniel Gultsch 2017-11-10 20:18:09 +01:00
parent f4638d7eec
commit d6eb08e0ed

View file

@ -14,6 +14,8 @@ import java.io.File;
public class FileUtils { public class FileUtils {
private static final Uri PUBLIC_DOWNLOADS = Uri.parse("content://downloads/public_downloads");
/** /**
* Get a file path from a Uri. This will get the the path for Storage Access * Get a file path from a Uri. This will get the the path for Storage Access
* Framework Documents, as well as the _data field for the MediaStore and * Framework Documents, as well as the _data field for the MediaStore and
@ -49,10 +51,12 @@ public class FileUtils {
else if (isDownloadsDocument(uri)) { else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri); final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId( try {
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); final Uri contentUri = ContentUris.withAppendedId(PUBLIC_DOWNLOADS, Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);
return getDataColumn(context, contentUri, null, null); } catch (NumberFormatException e) {
return null;
}
} }
// MediaProvider // MediaProvider
else if (isMediaDocument(uri)) { else if (isMediaDocument(uri)) {