当前位置: 首页 > 知识库问答 >
问题:

在android webview上启用输入文件摄像头

黄毅
2023-03-14
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="br.com.app...">

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
package br.com.app...;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

    private WebView webView;

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

        this.getSupportActionBar().hide();

        webView = findViewById(R.id.webView);
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("https://apps.url/loja/index.php");

        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
    }
}

共有1个答案

段干宾白
2023-03-14

首先,您应该在HTML文件中添加以下代码

<input type="button" value="Say hello" onClick="showAndroidCamera()" />

<script type="text/javascript">
    function showAndroidCamera() {
        Android.openCamera();
    }
</script>

在Android端创建一个类后

class WebAppInterface(private val mContext: Context) {

    /** Show a toast from the web page  */
    @JavascriptInterface
    fun openCamera() {
        //This method called when user clicks on webview button.
        Toast.makeText(mContext, open Camera, Toast.LENGTH_SHORT).show()
    }
}

并向webview添加WebAppInterface处理程序

webView.addJavascriptInterface(WebAppInterface(this), "Android")
public class MainActivity extends AppCompatActivity {

    private WebView webView;

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

        this.getSupportActionBar().hide();

        webView = findViewById(R.id.webView);
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("https://apps.url/loja/index.php");

        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
      webView.addJavascriptInterface(WebAppInterface(this), "Android")


    }
}
class WebAppInterface(private val mContext: Context) {

    /** Show a toast from the web page  */
    @JavascriptInterface
    fun openCamera() {
        //This method called when user clicks on webview button.
        Toast.makeText(mContext, open Camera, Toast.LENGTH_SHORT).show()
    }
}
 类似资料:
  • 我有表单在我的网站,接受文件输入。输入的代码在这里: 当我在我的笔记4上运行这个时,我只能选择相机应用程序来添加图像。我不能选择使用图片从画廊或照片。 在iPhone与Safari它完美的作品。它允许我选择从画廊或相机。我错过了什么?

  • 我正在开发一个应用程序,一个要求是用户可以从相机拍摄新照片或从图库中选择现有照片。我使用这个HTML5标签:

  • 问题内容: 我正在创建一个简单的表格,使用带有redux表格和材料ui的电子反应样板上传文件。 问题是我不知道如何创建输入文件字段,因为材料ui不支持上传文件输入。 关于如何实现这一目标的任何想法? 问题答案: 在结构上比@galki的解决方案更有意义的另一个> = v1.0解决方案。 在> = v1.0中已弃用。我找不到更多信息(可能没有记录?),但是当前的API 为此提供了信息。

  • 我正在使用CWAC-Camera库将自定义摄像头集成到我的应用程序中。 它工作正常,因为预期的所有设备,我有,除了在摩托罗拉E 当我使用上述设备捕获单镜头图像时,我没有得到所需大小的输出图像。 当我去拍摄单幅图像时,getLargestPictureSize(CameraUtils)方法返回相机支持的最大尺寸,如1944*2592(h*w)和拍摄前相同的相机参数集,但输出文件是用1280*720(

  • 我正在尝试使用GStreamer将RTMP/RTSP流连接到v4l2loopback虚拟设备。 工程1-RTMP至AutoVideoSink,sudo gst-launch-1.0 rtspsrc位置=rtsp://192.168.xxx.xxx/live/av0 ! decodebin!自动视频接收器sudo gst-launch-1.0 rtmpsrc位置=rtmp://192.168.xxx

  • 我在这个问题上遇到了几个问题。我正在尝试选择运行Chrome的Android设备上的后置摄像头。 因此,在阅读之后: 然后,因为我用了三个。在这个应用程序中,我将这个ID绑定到Jerome Etienne三分机网络摄像头抓取(https://github.com/jeromeetienne/threex.webar): 然后我不得不修改3X。网络摄像头抓取以这种方式分类(我删除了不相关的部分):