if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri);
if (id != null && id.startsWith("raw:")) { return id.substring(4); }
String[] contentUriPrefixesToTry = new String[]{ "content://downloads/public_downloads", "content://downloads/my_downloads" };
for (String contentUriPrefix : contentUriPrefixesToTry) { Uri contentUri = ContentUris.withAppendedId(Uri.parse(contentUriPrefix), Long.valueOf(id)); try { String path = getDataColumn(context, contentUri, null, null); if (path != null) { return path; } } catch (Exception e) { e.printStackTrace(); } } String fileName = getFileName(context, uri); File cacheDir = getDocumentCacheDir(context); File file = generateFileName(fileName, cacheDir); String destinationPath = null; if (file != null) { destinationPath = file.getAbsolutePath(); FileUtils1.saveFileFromUri(context, uri, destinationPath); }
return destinationPath; }