如何使用android webView打开相机

时间:2016-12-22 13:18:25

标签: android android-webview

我正在尝试使用android webView小部件打开相机。我google了很多次找到解决方案,但我找不到在android webview中打开相机的解决方案。这是我用过的代码。

    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

0 个答案:

没有答案