mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-01-19 03:42:52 +08:00
CB-14097: (android) Fix crash when selecting some files with getPicture (#322)
* CB-14097: (android) Fix crash when selecting some files with getPicture of urls with raw:// Handles both urls: content://com.android.providers.downloads.documents/document/1111 content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Ffilename.pdf * Optimization: Remove TextUtils dependency, return null when no id could be extracted
This commit is contained in:
parent
6899c5ece9
commit
5c23b65af9
@ -97,10 +97,21 @@ public class FileHelper {
|
|||||||
else if (isDownloadsDocument(uri)) {
|
else if (isDownloadsDocument(uri)) {
|
||||||
|
|
||||||
final String id = DocumentsContract.getDocumentId(uri);
|
final String id = DocumentsContract.getDocumentId(uri);
|
||||||
|
if (id != null && id.length() > 0) {
|
||||||
|
if (id.startsWith("raw:")) {
|
||||||
|
return id.replaceFirst("raw:", "");
|
||||||
|
}
|
||||||
|
try {
|
||||||
final Uri contentUri = ContentUris.withAppendedId(
|
final Uri contentUri = ContentUris.withAppendedId(
|
||||||
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
||||||
|
|
||||||
return getDataColumn(context, contentUri, null, null);
|
return getDataColumn(context, contentUri, null, null);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// MediaProvider
|
// MediaProvider
|
||||||
else if (isMediaDocument(uri)) {
|
else if (isMediaDocument(uri)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user