Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

Android-AdvancedWebView

> 编程语言
Open source

Enhanced WebView component for Android that works as intended out of the box

2.4K stars0 likes1 views
WebsiteGitHub

About

Enhanced WebView component for Android that works as intended out of the box

AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box

Requirements

  • Android 2.2+

Installation

  • Add this library to your project
    • Declare the Gradle repository in your root build.gradle

      gradle
      allprojects {
          repositories {
              maven { url "https://jitpack.io" }
          }
      }
    • Declare the Gradle dependency in your app module's build.gradle

      gradle
      dependencies {
          implementation 'com.github.delight-im:Android-AdvancedWebView:v3.2.1'
      }

Usage

AndroidManifest.xml

xml
<uses-permission android:name="android.permission.INTERNET" />

Layout (XML)

xml
<im.delight.android.webview.AdvancedWebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Activity (Java)

Without Fragments

…

With Fragments (android.app.Fragment)

Note: If you're using the Fragment class from the support library (android.support.v4.app.Fragment), please refer to the next section (see below) instead of this one.

…

With Fragments from the support library (android.support.v4.app.Fragment)

  • Use the code for normal Fragment usage as shown above

  • Change

    java
    mWebView.setListener(this, this);

    to

    java
    mWebView.setListener(getActivity(), this);
  • Add the following code to the parent FragmentActivity in order to forward the results from the FragmentActivity to the appropriate Fragment instance

    java
    public class MyActivity extends FragmentActivity implements AdvancedWebView.Listener {
    
     @Override
     public void onActivityResult(int requestCode, int resultCode, Intent intent) {
         super.onActivityResult(requestCode, resultCode, intent);
         if (mFragment != null) {
             mFragment.onActivityResult(requestCode, resultCode, intent);
         }
     }
    
    }

ProGuard (if enabled)

-keep class * extends android.webkit.WebChromeClient { *; }
-dontwarn im.delight.android.webview.**

Cleartext (non-HTTPS) traffic

If you want to serve sites or just single resources over plain http instead of https, there’s usually nothing to do if you’re targeting Android 8.1 (API level 27) or earlier. On Android 9 (API level 28) and later, however, cleartext support is disabled by default. You may have to set android:usesCleartextTraffic="true" on the <application> element in AndroidManifest.xml or provide a custom network security configuration.

Features

  • Optimized for best performance and security

  • Features are patched across Android versions

  • File uploads are handled automatically (check availability with AdvancedWebView.isFileUploadAvailable())

    • Multiple file uploads via single input fields (multiple attribute in HTML) are supported on Android 5.0+. The application that is used to pick the files (i.e. usually a gallery or file manager app) must provide controls for selecting multiple files, which some apps don't.
  • JavaScript and WebStorage are enabled by default

  • Includes localizations for the 25 most widely spoken languages

  • Receive callbacks when pages start/finish loading or have errors

    java
    @Override
    public void onPageStarted(String url, Bitmap favicon) {
        // a new page started loading
    }
    
    @Override
    public void onPageFinished(String url) {
        // the new page finished loading
    }
    
    @Override
    public void onPageError(int errorCode, String description, String failingUrl) {
        // the new page failed to load
    }
  • Downloads are handled automatically and can be listened to

…
  • Enable geolocation support (needs <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />)

    java
    mWebView.setGeolocationEnabled(true);
  • Add custom HTTP headers in addition to the ones sent by the web browser implementation

    java
    mWebView.addHttpHeader("X-Requested-With", "My wonderful app");
  • Define a custom set of permitted hostnames and receive callbacks for all other hostnames

    java
    mWebView.addPermittedHostname("example.org");

    and

    java
    @Override
    public void onExternalPageRequest(String url) {
        // the user tried to open a page from a non-permitted hostname
    }
  • Prevent caching of HTML pages

    java
    boolean preventCaching = true;
    mWebView.loadUrl("http://www.example.org/", preventCaching);
  • Check for alternative browsers installed on the device

    java
    if (AdvancedWebView.Browsers.hasAlternative(this)) {
        AdvancedWebView.Browsers.openUrl(this, "http://www.example.org/");
    }
  • Disable cookies

    java
    // disable third-party cookies only
    mWebView.setThirdPartyCookiesEnabled(false);
    // or disable cookies in general
    mWebView.setCookiesEnabled(false);
  • Allow or disallow (both passive and active) mixed content (HTTP content being loaded inside HTTPS sites)

    java
    mWebView.setMixedContentAllowed(true);
    // or
    mWebView.setMixedContentAllowed(false);
  • Switch between mobile and desktop mode

    java
    mWebView.setDesktopMode(true);
    // or
    // mWebView.setDesktopMode(false);
  • Load HTML file from “assets” (e.g. at app/src/main/assets/html/index.html)

    java
    mWebView.loadUrl("file:///android_asset/html/index.html");
  • Load HTML file from SD card

    java
    // <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        mWebView.getSettings().setAllowFileAccess(true);
        mWebView.loadUrl("file:///sdcard/Android/data/com.my.app/my_folder/index.html");
    }
  • Load HTML source text and display as page

    java
    myWebView.loadHtml("<html>...</html>");
    
    // or
    
    final String myBaseUrl = "http://www.example.com/";
    myWebView.loadHtml("<html>...</html>", myBaseUrl);
  • Enable multi-window support

…

Contributing

All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed.

License

This project is licensed under the terms of the MIT License.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javaandroidandroid-webviewmobilemobile-development

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言