[TIMOB-27406] Android: Cannot select content from downloads
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-01-10T16:57:50.000+0000 |
Affected Version/s | Release 8.0.0, Release 8.1.0, Release 8.2.0 |
Fix Version/s | Release 9.0.0 |
Components | Android |
Labels | android, engSchedule |
Reporter | Francisco Antonio Duran Ramirez |
Assignee | Gary Mathews |
Created | 2019-08-21T18:33:04.000+0000 |
Updated | 2020-01-10T16:57:50.000+0000 |
Description
I downloaded the following image to the device, so after that in the app I am selecting the image from the gallery of download, and it is causing a black/ gray window after selecting the image.
http://www.effigis.com/wp-content/uploads/2015/02/Airbus_Pleiades_50cm_8bit_RGB_Yogyakarta.jpg
The purpose of use this huge image it is that I am using the ti.imagefactory module to compress the image, but at the moment I am selecting the image downloaded the app is behaving in this way showing a black or gray window.
Note this issue is not happening in iOS.
XML:
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick">Hello, World</Label>
<ImageView id="mImageContainer" bottom="30"/>
</Window>
</Alloy>
JS:
function doClick(e) {
alert($.label.text);
Titanium.Media.openPhotoGallery({
success:function(event)
{
if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
Ti.API.info("success");
$.mImageContainer.image = event.media;
}
},
cancel: function(e){
Ti.API.info(e);
},
error:function(e) {
Ti.API.info(e);
},
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
});
}
$.index.open();
[ERROR] TiExceptionHandler: (main) [15193,15193] Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=co
ntent://com.android.providers.downloads.documents/document/raw:/storage/emulated/0/Download/x.jpg flg=0x1 }} to activity {com.tony.tony/or
g.appcelerator.titanium.TiActivity}: java.lang.NumberFormatException: For input string: "raw:/storage/emulated/0/Download/x.jpg"
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler: java.lang.Long.parseLong(Long.java:594)
[ERROR] TiExceptionHandler: java.lang.Long.valueOf(Long.java:808)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.io.TitaniumBlob.init(TitaniumBlob.java:89)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.io.TitaniumBlob.<init>(TitaniumBlob.java:41)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.io.TiFileFactory.createTitaniumFile(TiFileFactory.java:112)
[ERROR] TiExceptionHandler: ti.modules.titanium.media.MediaModule.createImageData(MediaModule.java:1276)
[ERROR] TiExceptionHandler: ti.modules.titanium.media.MediaModule.createDictForImage(MediaModule.java:1267)
[ERROR] TiExceptionHandler: ti.modules.titanium.media.MediaModule$1.onResult(MediaModule.java:1199)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.util.TiActivitySupportHelper$1.onResult(TiActivitySupportHelper.java:60)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.util.TiActivitySupportHelper.onActivityResult(TiActivitySupportHelper.java:117)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.TiBaseActivity.onActivityResult(TiBaseActivity.java:905)
[ERROR] TiExceptionHandler: android.app.Activity.dispatchActivityResult(Activity.java:7797)
[ERROR] TiExceptionHandler: android.app.ActivityThread.deliverResults(ActivityThread.java:5071)
[ERROR] TiExceptionHandler: android.app.ActivityThread.handleSendResult(ActivityThread.java:5120)
[ERROR] TiExceptionHandler: android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
[ERROR] TiExceptionHandler: android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
[ERROR] TiExceptionHandler: android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
[ERROR] TiExceptionHandler: android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
[ERROR] TiExceptionHandler: android.os.Handler.dispatchMessage(Handler.java:112)
[ERROR] TiExceptionHandler: android.os.Looper.loop(Looper.java:216)
[ERROR] TiExceptionHandler: android.app.ActivityThread.main(ActivityThread.java:7625)
[ERROR] TiExceptionHandler: java.lang.reflect.Method.invoke(Native Method)
[ERROR] TiExceptionHandler: com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
[ERROR] TiExceptionHandler: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
Please let me know whether you have any doubt or question.
Thanks, and best,
Francisco Antonio Duran Ramirez.
Attachments
File | Date | Size |
---|---|---|
1566788007519.JPEG | 2019-08-26T04:24:21.000+0000 | 43794 |
console.docx | 2019-08-26T04:25:54.000+0000 | 12043 |
Screenshot_20190822-135247.png | 2019-08-22T07:55:27.000+0000 | 2074056 |
Hello, Tested the sample code provide by you with SDK 8.1.0.GA on Android 7 device(Huawei y9 2018) and does not able to reproduce the issue. Can you please share the correct code? Test output: !Screenshot_20190822-135247.png|thumbnail!
Hello @Rakhi Mitro. Good afternoon / morning. Please download, and use the image I mentioned before with the following link: http://www.effigis.com/wp-content/uploads/2015/02/Airbus_Pleiades_50cm_8bit_RGB_Yogyakarta.jpg The size of this image (link provided) is 41MB approximately, and the image you are using is 2.1MB approximately, so it seems that the issue is when we are using an image with a huge size. Please let me know whether you have any doubt or question. Thanks, and best, Francisco Antonio Duran Ramirez.
[~antonioduran] [~rmitro] I think it is related to this: https://stackoverflow.com/questions/51136671/oreo-documentscontract-getdocumentiduri-returns-path-instead-of-long The problem is located in this line: https://github.com/appcelerator/titanium_mobile/blob/1a2343d1500a47ea5adabe8a52fcc077dd4b5169/android/titanium/src/java/org/appcelerator/titanium/io/TitaniumBlob.java#L89 and it is complaining about the parameter not beeing a number. Since [~antonioduran] is testing on Android 9 he has the problem while [~rmitro] is testing on Android 7 which should be fine (if the image was downloaded from the Cloud, so it wasn't physically on the device while clicking on it in the gallery)
Hello everyone. Last night this issue was reported on TiSlack by Diego Freniche (@dfreniche) and I explored the line of code where the exception is thrown. After googling a couple of sites, I realized that this is a known issue when accessing files located in downloads folder. Take a look at this SO entry: https://stackoverflow.com/questions/51136671/oreo-documentscontract-getdocumentiduri-returns-path-instead-of-long That's why I switched my forked Titanium_Mobile code to branch 8_1_X and tried a work around that fixes this behaviour. Basically I modified the org.appcelerator.titanium.io.TitaniumBlob.java class doing this:
Diego confirms it works. Please, consider this solution.
Please, consider update this issue title to "Issue opening files from downloads folder on Android 8+"
[~rfarfan] I've linked to the exact same issue some posts above :) Could have saved you some time. But at least you've tested it and made a PR! Please remove the commets "
phobeous - 2019.09.17 - TIMOB-27406 >> Start of modification
" from the PR and run "clang-format -style=file -i android/src/....filename
" to make the validator happyYeah. I visited this issue 3 or 4 weeks ago, but today I couldn't remember. Anyway, it took me more time building the SDK than searching on the web and apply the fix. Sorry for my silly comments in the code (it's my first PR ever). Comments are away now.
master: https://github.com/appcelerator/titanium_mobile/pull/11395
FR Passed, Waiting on Jenkins build.
merged to master for 9.0.0
Closing ticket, fix verified in SDK version
9.0.0.v20200109153329
. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/11395