CB-14097: (android) Fix crash when selecting some files with getPicture#322
CB-14097: (android) Fix crash when selecting some files with getPicture#322jcesarmobile merged 2 commits intoapache:masterfrom
Conversation
…re 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
|
Happened to me when selecting a photo from the Downloads folder. |
jcesarmobile
left a comment
There was a problem hiding this comment.
Looks good, but can you do the two changes I requested?
src/android/FileHelper.java
Outdated
| Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); | ||
|
|
||
| return getDataColumn(context, contentUri, null, null); | ||
| if (!TextUtils.isEmpty(id)) { |
There was a problem hiding this comment.
Instead of using TextUtils just for checking if is empty, use id != null && id.length() > 0
There was a problem hiding this comment.
Good idea to remove the dependency
| } catch (NumberFormatException e) { | ||
| return null; | ||
| } | ||
| } |
There was a problem hiding this comment.
if id is empty return null too
|
I have implemented the suggestions of the review. |
|
Thanks, merged! |
|
Is there a timeline for the next release? We're on 4.0.3 but this hasn't been merged in yet apparently. |
|
It’s merged, but not released |
|
Is there a timeline for the next release? |
|
This is very important, The camera is not working on a lot of android devices, When this will be released ? |
|
I need this fix. Please let me know how I can get around this problem. Is there a way I can manually apply this fix to my version of the plugin? |
android). PROBLEM, the plugins/cordova-plugin-camera has a bug in it that causes a problem with file paths (apache/cordova-plugin-camera#322). I had to add the fix manually then run the following commands: ionic cordova platform rm android (OR IOS) ionic cordova build android (OR IOS). Still need to implement the image upload.
|
I'm also facing this issue. We need this fix released! |
|
I'm also facing this issue. |
|
@claudiozam probably no timeline. I'm considering to use this repo directly to pull this fix to my code..... |
|
Actually we just got a release!!!! @claudiozam Thanks to @janpio ❤️ 🎉 |
|
Just a tag for now, release is in vote but will follow soon-ish. Watch for the |
|
@janpio isnt a tag a release? |
|
No, a tag is just a tag - but of course that can also be installed with the CLI. But doing |
|
Maybe its because I used ionic but |
|
Oh wait! I was wrong! Can we see the vote status? Where? Thanks! |
|
I solved it by editing the method "getRealPathFromURI_API11_And_Above" in this way: @SuppressLint("NewApi")
public static String getRealPathFromURI_API11_And_Above(final Context context, final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}
// TODO handle non-primary volumes
}
/* // DownloadsProvider
else if (isDownloadsDocument(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(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);
} catch (NumberFormatException e) {
return null;
}
} else {
return null;
}
}*/
// MediaProvider
else if (isMediaDocument(uri) || isDownloadsDocument(uri)) {
String docId = DocumentsContract.getDocumentId(uri);
docId = docId.replace("msf:", "video:");
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[]{
split[1]
};
return getDataColumn(context, contentUri, selection, selectionArgs);
}
}
// MediaStore (and general)
else if ("content".equalsIgnoreCase(uri.getScheme())) {
// Return the remote address
if (isGooglePhotosUri(uri))
return uri.getLastPathSegment();
return getDataColumn(context, uri, null, null);
}
// File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
} |
|
Hi @giuseeFG, your snippet helped me, thank you. |
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
Platforms affected
Android
What does this PR do?
Fixes crash of certain URLs
What testing has been done on this change?
manual testing
Checklist