[TIMOB-28057] Android: Modify WebView to use scoped storage for <input/> file selection
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-11-25T15:26:03.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 9.3.0 |
Components | Android |
Labels | WebView, android, file |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2020-07-30T03:14:57.000+0000 |
Updated | 2020-11-25T15:26:03.000+0000 |
Description
*Summary:*
If a webpage displayed by
Ti.UI.WebView
has an <input type="file"/>
element for taking camera photos, then our Android code will save the photo to "public" external storage which is no longer allowed due to Android's "scoped storage" rules. The photo must be saved to a different location.
*Note:*
An example on how to implement file/image selection in HTML can be found here...
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file
*To-Do:*
Our [TiWebChromeClient.java](https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiWebChromeClient.java) code needs to replace its usage of the following method call.
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
Best solution would be to let the camera app store the photo to its default location and use a ContentResolver
to retrieve an InputStream
to the photo.
There is also an Android 11 "package visibility" issue in our [TiWebChromeClient.java](https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiWebChromeClient.java) code where we use the Java resolveActivity()
method. We should remove our usage of this method since it will require a <query/>
element in the "AndroidManifest.xml" to work. Instead, wrap the startActivityForResult()
method call with a try/catch block in case no activity was found.
Attachments
File | Date | Size |
---|---|---|
flower.mp4 | 2020-09-12T03:12:28.000+0000 | 1128375 |
WebViewSelectImageTest.js | 2020-09-19T02:49:31.000+0000 | 1085 |
WebViewSelectVideoTest.js | 2020-09-19T02:49:31.000+0000 | 1172 |
PR (master): https://github.com/appcelerator/titanium_mobile/pull/12105
FR passed for this part of the PR
*Closing ticket*. Fix verified in SDK version
9.3.0.v20201125050632
. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/12105