1

I'm loading one URL in WebView, the URL page contains functionality of capturing image from device camera OR select image from gallery. If I open URL in Browser, everything works fine but, if I open the same URL in WebView then Camera and Gallery functionality do not works. I think I'm missing some WebView setting. Please check my below code and help me to solve my problem.

Below is my WebViewActivity--

public class WebViewActivity extends AppCompatActivity
{
    WebView myWebView;
    ProgressBar myProgress;

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

    private void findViews()
    {
        myWebView= (WebView) findViewById(R.id.myWebView);
        myProgress= (ProgressBar) findViewById(R.id.myProgress);
        myWebView.setWebViewClient(new myWebClient());
        myWebView.getSettings().setJavaScriptEnabled(true);
        myWebView.getSettings().setLoadWithOverviewMode(true);
        //Other webview settings
        myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        myWebView.setScrollbarFadingEnabled(false);
        myWebView.getSettings().setBuiltInZoomControls(true);
        myWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
        myWebView.getSettings().setAllowFileAccess(true);
        myWebView.getSettings().setSupportZoom(true);

        myWebView.loadUrl(SafeNestConstants.MEDLIFE_URL);
    }

    public class myWebClient extends WebViewClient
    {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon)
        {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
        }

        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
        {
            myProgress.setVisibility(View.VISIBLE);
            view.loadUrl(request.getUrl().toString());
            return true;
        }
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            // TODO Auto-generated method stub
            myProgress.setVisibility(View.VISIBLE);
            view.loadUrl(url);
            return true;

        }

        @Override
        public void onPageFinished(WebView view, String url)
        {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
            myProgress.setVisibility(View.GONE);
        }
    }
}

Below is my activity_my_webview.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_terms_and_conditions"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.mypackage.WebViewActivity">

    <WebView
        android:id="@+id/myWebView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </WebView>

    <ProgressBar
        android:id="@+id/myProgress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:indeterminateDrawable="@drawable/progress_medium"
        android:visibility="visible" />
</RelativeLayout>

Also let me know if I can provide more information for the same. Thank you.

Dnyanesh M
  • 1,349
  • 4
  • 18
  • 46
  • http://stackoverflow.com/questions/23568792/android-4-4-webview-file-chooser-not-opening – Pavya May 04 '17 at 04:55

0 Answers0