2

I am trying to open a camera using android webView widget. I googled many times to find out a solution but i could not findout a solution to open a camera in android webview.Here is the code i have used.

    public class ShowWebView extends Activity {
    private WebView myWebView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.show_web_view);
    // Find the web view in our layout xml
    myWebView = (WebView) findViewById(R.id.webView1);


    // Settings
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccessFromFileURLs(true);
    webSettings.setAllowUniversalAccessFromFileURLs(true);
    webSettings.setAllowFileAccess(true);

    // Set a web view client and a chrome client
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.setWebChromeClient(new WebChromeClient() {
    // Need to accept permissions to use the camera and audio
    @Override
    public void onPermissionRequest(final PermissionRequest request) {
    Log.d(TAG, "onPermissionRequest");
    request.grant(request.getResources());
    myWebView.loadData(summary, "text/html", null);
    }



    }

   The following are the permission set in AndroidManifest.xml file

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />


    layout File

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

   <WebView
        android:id="@+id/webView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
  </LinearLayout>


    Could some one please help me out how to open a camera in web View on Android 6.0
shiva oleti
  • 775
  • 3
  • 16
  • 23
  • [http://stackoverflow.com/questions/5803914/can-i-open-camera-in-webview](http://stackoverflow.com/questions/5803914/can-i-open-camera-in-webview) Visit this link. It may help you. – Sneha Sarkar Dec 22 '16 at 13:22
  • Hi,I copy and pasted the example as it is defined in the " http://androidexample.com/Open_File_Chooser_With_Camera_Option_In_Webview_File_Option/index.php?view=article_discription&aid=128&aaid=148 " .But it's not working for me. – shiva oleti Dec 22 '16 at 13:35

0 Answers0