Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Access Local File From WebView Javascript

I am looking for an elegant way to access local files (either on phone memory or SD Card) on an Android device from JavaScript running in WebView on an Android device.

I am loading said WebView with a html page from the device located in the assets folder. Along these lines, I believe I can access any file in this assets folder from the Javascript, but can't load anything from SD card or phone memory. I am aware of the addJavaScriptInterface, but I am specifically trying to load images, so using this method would require some tweaking to pass a B64 encoded image.

I am new to Android development, and want to make sure I am not missing something obvious.

like image 712
user163757 Avatar asked Oct 11 '25 07:10

user163757


1 Answers

You need to implement a ContentProvider to map local files to uris.

like image 84
basicsharp Avatar answered Oct 13 '25 20:10

basicsharp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!