Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28057] Android: Modify WebView to use scoped storage for <input/> file selection

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2020-11-25T15:26:03.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.3.0
ComponentsAndroid
LabelsWebView, android, file
ReporterJoshua Quick
AssigneeJoshua Quick
Created2020-07-30T03:14:57.000+0000
Updated2020-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

FileDateSize
flower.mp42020-09-12T03:12:28.000+00001128375
WebViewSelectImageTest.js2020-09-19T02:49:31.000+00001085
WebViewSelectVideoTest.js2020-09-19T02:49:31.000+00001172

Comments

  1. Joshua Quick 2020-09-19

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/12105
  2. Sohail Saddique 2020-10-08

    FR passed for this part of the PR
  3. Samir Mohammed 2020-11-25

    *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

JSON Source