0

In my application I am using webview and in that I am opening the url "drive.google.com/keep" And while creating notes in the webpage, there is an option of choosing the image from gallery, And while I click on that to choose the image nothing happens and App stays there without doing anything. While in Web browser it is opening the gallery correctly. I think I am missing to enable something which I don't know. Here is my code :

Activity Code:

public void webviewSetup() {
    setContentView(R.layout.activity_main);

    CookieSyncManager.createInstance(this);

    keepWebView = (WebView) findViewById(R.id.activity_main_webview);

    keepWebView.addJavascriptInterface(keepWebView, url);
    WebSettings webSet = keepWebView.getSettings();
    webSet.setJavaScriptEnabled(true);

    final ProgressBar pb = getProgressBar();
    if (pb != null)
        pb.setVisibility(View.VISIBLE);
    // Enabling local database
    webSet.setDatabaseEnabled(true);

    // Enable manifest cache.
    String cachePath = this.getApplicationContext()
            .getDir("cache", Context.MODE_PRIVATE).getPath();
    webSet.setAppCachePath(cachePath);
    webSet.setAllowFileAccess(true);
    webSet.setAppCacheEnabled(true);
    webSet.setDomStorageEnabled(true);
    // webSet.setAppCacheMaxSize(1024 * 1024 * 8);
    webSet.setCacheMode(WebSettings.LOAD_DEFAULT);

    // loads the url
    keepWebView.loadUrl(url);
    keepWebView.setWebViewClient(new KeepWebViewClient(this, keepWebView,
            pb));
}

And my KeepWebViewClient.class

public class KeepWebViewClient extends WebViewClient {
Activity activity;
WebView wv;
View pd;

public KeepWebViewClient(Activity activity, WebView wv, View pd) {
    this.activity = activity;
    this.wv = wv;
    this.pd = pd;
}

@Override
public boolean shouldOverrideUrlLoading(WebView mWebView, String url) {
    mWebView.loadUrl(url);
    return true;
}

@Override
public void onPageFinished(WebView view, String url) {
    if (pd != null)
        pd.setVisibility(View.GONE);

    CookieSyncManager.getInstance().sync();
    super.onPageFinished(view, url);
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    Log.d("GoogleApps", "loading " + url);

    if (pd != null)
        pd.setVisibility(View.VISIBLE);
    super.onPageStarted(view, url, favicon);
}
}

Any help would be really appreciated. Thanks

nadeem gc
  • 484
  • 1
  • 8
  • 22

1 Answers1

0

You aren't doing anything wrong. The mechanism that the Browser uses to support file uploads (and picking an item from the gallery) is not a public API that is available to WebView apps.

That said, you can use some tricks to get the behaviour you want; however please be aware that these tricks do not work in Android 4.4, and there is no workaround for supporting file uploads in WebView on KitKat.

ksasq
  • 4,424
  • 2
  • 18
  • 10