Coder Social home page Coder Social logo

delight-im / android-advancedwebview Goto Github PK

View Code? Open in Web Editor NEW
2.4K 89.0 573.0 438 KB

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

License: MIT License

Java 100.00%
android webview android-webview mobile mobile-development web web-app web-application

android-advancedwebview's Introduction

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

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

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

Usage

AndroidManifest.xml

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

Layout (XML)

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

Activity (Java)

Without Fragments

public class MyActivity extends Activity implements AdvancedWebView.Listener {

    private AdvancedWebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        mWebView = (AdvancedWebView) findViewById(R.id.webview);
        mWebView.setListener(this, this);
        mWebView.setMixedContentAllowed(false);
        mWebView.loadUrl("http://www.example.org/");

        // ...
    }

    @SuppressLint("NewApi")
    @Override
    protected void onResume() {
        super.onResume();
        mWebView.onResume();
        // ...
    }

    @SuppressLint("NewApi")
    @Override
    protected void onPause() {
        mWebView.onPause();
        // ...
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        mWebView.onDestroy();
        // ...
        super.onDestroy();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        mWebView.onActivityResult(requestCode, resultCode, intent);
        // ...
    }

    @Override
    public void onBackPressed() {
        if (!mWebView.onBackPressed()) { return; }
        // ...
        super.onBackPressed();
    }

    @Override
    public void onPageStarted(String url, Bitmap favicon) { }

    @Override
    public void onPageFinished(String url) { }

    @Override
    public void onPageError(int errorCode, String description, String failingUrl) { }

    @Override
    public void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent) { }

    @Override
    public void onExternalPageRequest(String url) { }

}

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.

public class MyFragment extends Fragment implements AdvancedWebView.Listener {

    private AdvancedWebView mWebView;

    public MyFragment() { }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_my, container, false);

        mWebView = (AdvancedWebView) rootView.findViewById(R.id.webview);
        mWebView.setListener(this, this);
        mWebView.setMixedContentAllowed(false);
        mWebView.loadUrl("http://www.example.org/");

        // ...

        return rootView;
    }

    @SuppressLint("NewApi")
    @Override
    public void onResume() {
        super.onResume();
        mWebView.onResume();
        // ...
    }

    @SuppressLint("NewApi")
    @Override
    public void onPause() {
        mWebView.onPause();
        // ...
        super.onPause();
    }

    @Override
    public void onDestroy() {
        mWebView.onDestroy();
        // ...
        super.onDestroy();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        mWebView.onActivityResult(requestCode, resultCode, intent);
        // ...
    }

    @Override
    public void onPageStarted(String url, Bitmap favicon) { }

    @Override
    public void onPageFinished(String url) { }

    @Override
    public void onPageError(int errorCode, String description, String failingUrl) { }

    @Override
    public void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent) { }

    @Override
    public void onExternalPageRequest(String url) { }

}

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

  • Use the code for normal Fragment usage as shown above

  • Change

    mWebView.setListener(this, this);

    to

    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

    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

    @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

    @Override
    public void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent) {
        // some file is available for download
        // either handle the download yourself or use the code below
    
        if (AdvancedWebView.handleDownload(this, url, suggestedFilename)) {
            // download successfully handled
        }
        else {
            // download couldn't be handled because user has disabled download manager app on the device
            // TODO show some notice to the user
        }
    }
  • Enable geolocation support (needs <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />)

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

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

    mWebView.addPermittedHostname("example.org");

    and

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

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

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

    // 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)

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

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

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

    // <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

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

    myWebView.getSettings().setSupportMultipleWindows(true);
    // myWebView.getSettings().setJavaScriptEnabled(true);
    // myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    
    myWebView.setWebChromeClient(new WebChromeClient() {
    
        @Override
        public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
            AdvancedWebView newWebView = new AdvancedWebView(MyNewActivity.this);
            // myParentLayout.addView(newWebView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
            transport.setWebView(newWebView);
            resultMsg.sendToTarget();
    
            return true;
        }
    
    }

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.

android-advancedwebview's People

Contributors

afollestad avatar meniks avatar ocram avatar passos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-advancedwebview's Issues

File uploads in WebView not working on KitKat (4.4.0->4.4.2)

This is probably a VERY known issue (and might even be unsolvable). But I thought I'd make an issue about it so that people know it won't work for KitKat 4.4.0->4.4.2. Also maybe update the README.md to state this?

It should work in KitKat 4.4.3+ though, but I haven't tested it myself.

Issue with activity being recreated when receiving file upload result

At a small number of users I noticed that the system has to recreate the activity before delivering the result through onActivityResult(...). This means that also a new AdvancedWebView will be created, which won't have the same mFileUploadCallbacks as the original one. Is there a way to persist these, that the WebView could receive them even if it gets recreated?

File Download

file download is not working for me when i click download button nothing happens ... file upload works great

webview.addhttpheader issue

hello,

i tested this AdvancedWebView.. it works nice
but i have a problem

when i addheader "X-Requested-With","somthing"
it add header works
but when url load resources like or or
X-Requested-With header was "my.app.id"
how can i addheader for every requests and resource in requests?

There is no Get Header method.

I'm trying to get header response on web view but in AdvancedWebVIew this feature is not included. Can you add this feature?

Problem to cast the AdvancedWebView

I have so many issues with the openFileChooser because im using a webview so. I decided to use your AdvaneWebView and im having this problem with the cast of the webview. I would apreciate if you could help me with this issue. Thanks

ERROR:

7954-7954/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.pinttag.pinttag, PID: 7954
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pinttag.pinttag/com.pinttag.pinttag.MainActivity}: java.lang.ClassCastException: im.delight.android.webview.AdvancedWebView cannot be cast to com.pinttag.pinttag.AdvancedWebView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2790)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
at android.app.ActivityThread.access$900(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6117)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.ClassCastException: im.delight.android.webview.AdvancedWebView cannot be cast to com.pinttag.pinttag.AdvancedWebView
at com.pinttag.pinttag.MainActivity.onCreate(MainActivity.java:53)
at android.app.Activity.performCreate(Activity.java:6374)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2743)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
            at android.app.ActivityThread.access$900(ActivityThread.java:181)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:6117)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)

            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

Main_Activity:

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;

public class MainActivity extends Activity implements AdvancedWebView.Listener {

private AdvancedWebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebView = (AdvancedWebView) findViewById(R.id.webview);
    mWebView.setListener(this, this);
    mWebView.loadUrl("http://www.pinttag.com");

    // ...
}

@SuppressLint("NewApi")
@Override
protected void onResume() {
    super.onResume();
    mWebView.onResume();
    // ...
}

@SuppressLint("NewApi")
@Override
protected void onPause() {
    mWebView.onPause();
    // ...
    super.onPause();
}

@Override
protected void onDestroy() {
    mWebView.onDestroy();
    // ...
    super.onDestroy();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    mWebView.onActivityResult(requestCode, resultCode, intent);
    // ...
}

@Override
public void onBackPressed() {
    if (!mWebView.onBackPressed()) { return; }
    // ...
    super.onBackPressed();
}

@Override
public void onPageStarted(String url, Bitmap favicon) { }

@Override
public void onPageFinished(String url) { }

@Override
public void onPageError(int errorCode, String description, String failingUrl) { }

@Override
public void onDownloadRequested(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { }

@Override
public void onExternalPageRequest(String url) { }

}

LAYOUT

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

CookieSyncManager support

@Vissanu asked:

Is this libs has a CookieSync? I wanna pass a cookie to URL for auto login by token.
Something like this code :

CookieSyncManager.createInstance(ActivityName.this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookie();
String token = session.User_status;
String cookieString = "s_admin="+ token;
cookieManager.setCookie("lhttp://abc-site.com", cookieString);
CookieSyncManager.getInstance().sync();

But it isn't work for me. Can you help me?

@Vissanu First, please open a separate issue for any new problem or question.

This library doesn't use CookieSyncManager in any way because it is completely separate. You can freely use it in addition to the library without having to change the library's code.

Thus, for your specific problem, we cannot help here, unfortunately. But you may read the docs or get help on Stack Overflow where they seem to have discussed your problem already.

File uploads not working out of the box

Are there any steps that need to be taken to enable file uploads?

The app is working (after a minor tweak of adding the Listener's static methods to Activity class itself instead of in mWebView.setListener and adding some code so external links would open) but clicking a file upload button triggers no action out of the box.

The page I use for testing has a regular file upload field. When I click the button in Chrome browser on my phone (or on my desktop) the file dialog box opens and I'm able to upload a file. When I click it inside the App, no luck.

The same testpage also has a fancy Bootstrap uploader (https://github.com/kartik-v/bootstrap-fileinput) - with same results.

Custom headers not sent with every request

How do you manipulate request URL before it is sent?
My guess is that I need to do override a method in the WebViewClient but I have no way of doing that since you do not expose the WebViewClient.

Is there a workaround?

Thanks

EDIT: Found "setWebViewClient" method.

Android 4.4.2 with Input type=file

Greeting,
This AdvancedWebView seems cannot work on Android 4.4.2(ASUS ZenFone and BlueStack Simulator) with html input type=file ? I tried From 4.1(API 16) to 6.0(API 23) with Emluator or HTC devices. But Android 4.4 has no response as I press the INPUT TYPE=FILE , on function.

您好,請問一下,它是不是在Android 4.4.2 (ASUS ZenFone and BlueStack Simulator) 時,在上傳檔案這的功能,會無法正常運作?我試了4.1(Emluator,API 16) , 4.2.2(HTC one SV, API 17), 4.3(Emluator , API 18) , 5.0(Emluator,API 21) ,5.1(HTC One M7, API 22) , 6.0(HTC One M8,API 23) , 它們都可以正常回應 INPUT TYPE=FILE的openFileChooser,但是API 19的4.4沒有反應…

Multiple file upload?

Hello, thanks for the great job.

How can I enable multiple file select?
My HTML input element has the multiple attribute set, but it is only allowing one file to be selected!

any advice please?

Out of the box: Listener methods

Following the steps in the readme, Android Studio still threw warnings the Activity must be either abstract or implement AdvancedWebView's Listener methods.

It stopped complaining when I copied the methods from mWebView.setListener to the Activity class and commented out the mWebView.setListener part in onCreate altogether.

@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
}

@Override
public void onDownloadRequested(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
    // some file is available for download
}

@Override
public void onExternalPageRequest(String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    mWebView.getContext().startActivity(intent);
}

(I added the Intent to onExternalPageRequest to be able to have external links open in my phone's browser)

How to handle download automatically in webview

In README.md ur given this

  • Downloads are handled automatically and can be listened to

    @Override
    public void onDownloadRequested(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
       // some file is available for download
       // either handle the download yourself or use the code below
    
       final String filename;
       // ...
    
       if (AdvancedWebView.handleDownload(this, url, filename)) {
           // download successfully handled
       }
       else {
           // download couldn't be handled because user has disabled download manager app on the device
           // TODO show some notice to the user
       }
    }
    
    Can you please provide how to handle download and what is  final String filename.
    ![screenshot 3](https://cloud.githubusercontent.com/assets/12455657/7647492/9272a87e-faf7-11e4-80c9-5bf6260a36b8.png)
    

java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode

This error is thrown when pressing an upload field (input type='file'). The error is quite straight forward and is probably easily fixed. (Android 4.2 and 5.0.1 tested)

java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:815) at im.delight.android.webview.AdvancedWebView.openFileInput(AdvancedWebView.java:396) at im.delight.android.webview.AdvancedWebView$2.openFileChooser(AdvancedWebView.java:243) at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:844) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5039) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method)

Camera access permission

Is there a way to give my android app camera access permission?
Like mWebView.setGeolocationEnabled(true) for location permission, is there anything like it to allow the camera access?

JavaScript alert can not load in webView for android L Devices

Data is loaded from iFrame to android application, there is javascript dialog in iFrame for some task. all working fine in all other devices excluding Android Lollipop devices.

JavaScript Alert is not working in above api 20 in this webview.

Can you please help to show javascript dialog in Android Api >19 ?

Logcat Says "Cannot create a dialog, the WebView context is not an Activity"

Progress loading cannot dissmiss

This is my snippet code:

public class MainActivity extends AppCompatActivity implements AdvancedWebView.Listener {
    private AdvancedWebView mWebView;
    private ProgressDialog pd;

On Page Started:

    public void onPageStarted(String url, Bitmap favicon) {
        pd = ProgressDialog.show(this, "", "Loading...", true);
    }

On Page Finished:

    public void onPageFinished(String url) {
        if(pd != null && pd.isShowing()) {
           pd.dismiss();
        }
        Toast.makeText(this, "Loaded", Toast.LENGTH_SHORT).show();
    }

The loading is always show, even "Loaded" message has been shown.
How to figure out this?
Did anyone implement this loading feature?

Thank You

How to use shouldOverrideUrlLoading

I want to check URL param (internal URL), if contains some "string", then do not load url, and display an Alert.

And for external URL, how to implement to go to default client Browser.

Thank You

file not uploading getting error:

after pressing upload i am getting the following error

01-29 04:24:11.385 32115-32115/com.example.bikesh.webviewexample I/chromium: [INFO:CONSOLE(12)] "Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png", source: data:text/html,chromewebdata (12)

Not found method shouldInterceptRequest

I try using shouldInterceptRequest method by extending WebViewClient with below class:
private class MyWebViewClient extends WebViewClient{ @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { Log.d("shouldInterceptRequest", "url: " + url); return super.shouldInterceptRequest(view, url); } }

And set it to AdvancedWebView with below code:
mWebView.setWebViewClient(new MyWebViewClient());

But when I'm start loading the webpage, nothing happens in shouldInterceptRequest.

And I found error "could not found method shouldInterceptRequest" in debug window.

But using generic WebView shouldInterceptRequest is called.

Html5 download tag

Hello,

I was wondering if the AdvancedWebView supports this kind of html

Because when I click on it nothing happen and it works perfectly on chrome and other browsers.

There is anything specify that I have to do to make it work?

Thanks!

iFrame URL click issue

Hi there

Thanks for the great webview. While using this webview, we are facing an issue with external link URLs inside iFrame. In our case, there are multiple iframes on a webpage www.unlockar.com/horoscope. When one clicks on the link 'Read the article on astrocenter.com' the target url opens up in the same iframe. While opening this link in chrome, it opens up the target url in another tab.

I want to sort this issue out by bringing a new webview with target url in front of user.

File uploading problem

I'm trying to implement file uploading in an app, and I'm testing on a phone with Android 5.0.1.

When I click the upload button, I can choose a file that i need, but after i select it, it doesn't appear selected in browser (this is how the looks like after i select the image:
image
)

Also, i have added <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> in my manifest file.

Any help is appreciated :)

Arabic custom font

Hi,
Android webView can render custom english fonts without any issue. this is not the case in custom Arabic font. here the webView looks for the default system Arabic font and renders it. it ignores any defined custom font.
Can you please bring a solution for this issue in your Android-AdvanceWebView?

Thanks

Question

it loads my page but after some seconds it automatically redirects to some other pages which does not belonged to my website.. plz help

Image names are altered.

It works fine for me but it alter the image name.
When I select image from browser "Attach file" , It alter the image name something like "image%xxxx"
Here xxxx are any random numbers.

Note : I'm selecting image with default name like "sample.png".

I've tried to choose different image but problem is same.

Any solution ?

White screen and nothing shows

Hi,
Thank you for your efforts.
I'm trying to use your awesome library but I'm getting white page most of the time.
I tried it with m.facebook.com and my site doblist.com they are the same.
I'm trying the sample included with the library.
And I noticed that it's more slow than the original webView
I tried my m.facebook.com and my site on the original and they are working fine.
In the library it show a toast with "Finished loading" then a toast with the title but nothing shows in the webview.
Thank you very much

New methods on API 21

Hi,

Is there some plan to introduce the methods introduced on WebView (API 21) or this will be up to the user-developer?

I'm mean something like

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void acceptThirdPartyCookies(boolean enabled) {

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      CookieManager cookieManager = CookieManager.getInstance();
       cookieManager.setAcceptThirdPartyCookies(this, enabled);
  }
}

I can create a pull request if needed.

Great library :)

Can this fix the problem with file upload in webview?

Hi, I was trying to use your script to fix the problem with filechooser for example:
if I open this page in the browser http://www.francesco.iovine.name/w3c/mediacapture/ and try to upload something it's works the way it should.

But in your script it takes me to the choose a recent document instead of choose an application to complete the action. Like Camera or Audio Recorder.

I feel like I'm doing something wrong, but want to make sure, I spend so much time on this problem, all I'm trying to do is to load one page inside the app and make input field work the way it should.

I would appreciate for any help. Thank you

input file upload not working on android 4.4.X

Hi Author,
Really it is great tool to over come all issues with default webview. i am having one problem. i have webpage which has file input. i am loading this webpage into your webview. it is working fine in other version. but in android 4.4, it is not showing filechooser. how to fix this issue please guide me.

Missing content_type in file upload with Android 4.4.4

Hello,

I am trying to upload images via a WebView in Android. Both your implementation as http://stackoverflow.com/questions/5907369/file-upload-in-webview are not properly working for me with Android 4.4.4. Here is an extract from the received data:

Android 4.4.4

Parameters: {"utf8"=>"✓", "authenticity_token"=>"Vximz1fjqQcRpeYvek3G3tfK2L9wiQQSm837Zj5+aBI=", "item"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007f2e49ab35f0 @tempfile=#<Tempfile:/tmp/RackMultipart20150228-10308-h8g0yc>, @original_filename="image:1641", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"item[image]\"; filename=\"image%3A1641\"\r\nContent-Type: application/octet-stream\r\n">, "description"=>"", "for_friends"=>"0", "for_family"=>"0", "for_acquaintances"=>"0"}, "commit"=>"Speichern", "user_id"=>"1"}

Android 5.0

Parameters: {"utf8"=>"✓", "authenticity_token"=>"f/5PkwJ+g/30G7oWrsUizn0Lh7jzMsGMxnz264NorzQ=", "item"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007f2e4a771710 @tempfile=#<Tempfile:/tmp/RackMultipart20150228-10308-1uacuce>, @original_filename="IMG_20150228_161113.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"item[image]\"; filename=\"IMG_20150228_161113.jpg\"\r\nContent-Type: image/jpeg\r\n">, "description"=>"", "for_friends"=>"0", "for_family"=>"0", "for_acquaintances"=>"0"}, "commit"=>"Speichern", "user_id"=>"1"}

The problem is the missing content type. Not even the filename has a content type extension. I tried things like setting the content type in the WebView manually with

setType("image/jpeg");

But that approach doesn't work. Perhaps you know a solution for this issue. Thanks!

I cannot build a Signed APK

Hi! Thanks for your work!
I would add your webview to my project (SlimSocial for Facebook).
I have added all and all works but I can only do the debug on my telephone because when I try to build an APK I have:

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Can't write [C:\Users\Leo\Source\Repos\SlimFacebook\SlimFacebook - alpha\app\build\intermediates\transforms\proguard\release\jars\3\1f\main.jar] (Can't read [C:\Users\Leo\Source\Repos\SlimFacebook\SlimFacebook - alpha\app\build\intermediates\classes\release(;;;;;;**/*.class)] (Duplicate zip entry [im/delight/android/webview/a.class == im/delight/android/webview/AdvancedWebView$1.class]))

My gradle code:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

My app gradle code:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "it.rignanese.leo.slimfacebook"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 29
        versionName "2.2.4 APLPHA"
    }
    buildTypes {
        debug {
            minifyEnabled true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            zipAlignEnabled true
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        disable 'MissingTranslation'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.github.delight-im:Android-AdvancedWebView:v2.1.0'
    compile 'com.android.support:appcompat-v7:23.1.0'
}

On my proguard-rules.pro

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

How can I solve this? Maybe there is incompatibility but I cannot find it :\
Thanks

Screen goes white when click on youtube's fullscreen button

hello

Firstly thank you for creating this. Actually i'm using your lib in making a web view based app in which some youtube video should play. videos are playing but when i click on full screen mode the screen goes white but audio still stream
screenshot_2016-03-30-02-33-46
screenshot_2016-03-30-02-33-52

Progress bar / Title Bar

Hello, thanks for providing this framework, it works great. I was wondering if you were planning on adding the ability to display a progress bar and title bar?

Fatal Error - App Crash Log

Receiving fatal error when accessing just the fragment that the AdvancedWebView should be on... I have AdvancedWebView.java source in it's own file. Not using the main java onCall, just another fragment to display the AdvancedWebView. Any ideas? The Line 26 it mentions is the rootView = inflater.inflate.... etc etc. line.

Here's the error:

: FATAL EXCEPTION: main
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime: Process: com.test.app, PID: 27247
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime: android.view.InflateException: Binary XML file line #6: Error inflating class im.delight.android.webview.AdvancedWebView
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at com.test.app.report2_Fragment.onCreateView(report2_Fragment.java:26)

Caused by: java.lang.ClassNotFoundException: Didn't find class "im.delight.android.webview.AdvancedWebView" on path: DexPathList[[zip file "/data/app/com.test.app-2/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at android.view.LayoutInflater.createView(LayoutInflater.java:578)
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:813) 
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:511) 
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at com.test.app.report2_Fragment.onCreateView(report2_Fragment.java:26) 
10-18 16:43:36.821 27247-27247/com.test.app E/AndroidRuntime:     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962) 

Here's the fragment:

package com.test.app;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;



public class report2_Fragment extends Fragment implements AdvancedWebView.Listener {

    private AdvancedWebView mWebView;

    public report2_Fragment() { }
    View rootView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.report2, container, false);

        mWebView = (AdvancedWebView) rootView.findViewById(R.id.webview);
        mWebView.setListener(getActivity(), this);
        mWebView.loadUrl("http://www.example.org/");

        // ...

        return rootView;
    }

    @SuppressLint("NewApi")
    @Override
    public void onResume() {
        super.onResume();
        mWebView.onResume();
        // ...
    }

    @SuppressLint("NewApi")
    @Override
    public void onPause() {
        mWebView.onPause();
        // ...
        super.onPause();
    }

    @Override
    public void onDestroy() {
        mWebView.onDestroy();
        // ...
        super.onDestroy();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        mWebView.onActivityResult(requestCode, resultCode, intent);
        // ...
    }

    @Override
    public void onPageStarted(String url, Bitmap favicon) { }

    @Override
    public void onPageFinished(String url) { }

    @Override
    public void onPageError(int errorCode, String description, String failingUrl) { }

    @Override
    public void onDownloadRequested(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { }

    @Override
    public void onExternalPageRequest(String url) { }

}

Cannot call determinedVisibility() - never saw a connection for the pid.

When I try to load "http://convert2mp3.net" with loadurl("") method, nothing happens and logcat (in eclipse) it says "W/cr.BindingManager(31239): Cannot call determinedVisibility() - never saw a connection for the pid".

In forums, people says "set setdomstorageenabled true", but it is not working (even it is defaultly true in AdvancedWebView).

This problem only occurs Android 4.4 and above.

Please help.
Thanks

FileUpload on Android 4.4.2 does not work

Just tried your code on my LG G2 running Android 4.4.2 with an html containing input type=fileupload.
Unfortunately nothing happend, when I clicked on the "Upload" Button.

Kind regards,
Dirk

Choose an action for input

Hello,
I want to use the camera as input device for images. For the HTML I tried following approaches:

 <input type="file" accept="image/*">
 <input type="file" accept="image/*;capture=camera">
 <input type="file" accept="image/*" capture="camera">

In the Android Browser it works great with API Level 15 and 21. But in the WebView, it is not possible to use the camera directly, like you know from a native app.

API 15
https://cloud.githubusercontent.com/assets/2969758/6741622/69f1b7c2-ce89-11e4-995b-7f5af0d596a8.png
https://cloud.githubusercontent.com/assets/2969758/6741623/69f6f4f8-ce89-11e4-9668-b37db04c2c31.png

API 21
https://cloud.githubusercontent.com/assets/2969758/6741624/69f87422-ce89-11e4-9528-3d4adb67cb76.png
https://cloud.githubusercontent.com/assets/2969758/6741625/69fa6c78-ce89-11e4-8fc4-f58da3d25a6a.png

I also added the camera permission to the manifest:

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

Perhaps you know, how I have to change this in der WebView. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.