Android Access Local File From WebView Javascript

13,670

Solution 1

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

Solution 2

Android tip #1 ContentProvider , Accessing local file system from WebView / showing image in webview using content://

Share:
13,670
user163757
Author by

user163757

Updated on July 29, 2022

Comments

  • user163757
    user163757 almost 2 years

    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.

  • jasonflaherty
    jasonflaherty over 11 years
    That link is broken, but Archive.org has it here: web.archive.org/web/20101108043507/http://www.techjini.com/b‌​log/…
  • Tapemaster
    Tapemaster about 8 years
    The web link mentioned is broken. That's why it's always a good idea to provide an answer inline.