android - 我可以在 WebView 中打开相机吗?

标签 android camera cordova android-webview android-camera

我可以在 webview 中打开 android 摄像头吗?

最佳答案

使用 Webview 时获得相机功能的最简单方法是使用 Intent。

如果您使用 API,则必须自己构建大量 UI。这是好是坏取决于您需要在应用程序中做什么以及您需要对“拍照过程”进行多少控制。如果您只需要一种快速拍摄照片并在您的应用程序中使用它的方法,Intent 就是您的不二之选。

Intent 示例:

private Uri picUri;
private void picture()
{
     Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
     File photo = new File(Environment.getExternalStorageDirectory(), "pic.jpg");
     cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
     picUri = Uri.fromFile(photo);
     startActivityForResult(cameraIntent, TAKE_PICTURE);
}

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode){
        case TAKE_PICTURE:
            if(resultCode == Activity.RESULT_OK){
                Uri mypic = picUri;
                //Do something with the image.
            }
}

我最初从另一个答案中借用了这个示例的部分内容来构建它。但我没有网址了。

在我现在编写的应用程序中,我将此图像转换为 Base64,然后将其传递给 Javascript,然后将其发布到我的服务器。但是,这可能比您需要知道的更多。 :)

here是使其在 webView 上工作的链接

关于android - 我可以在 WebView 中打开相机吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5803914/

相关文章:

android - 如何在执行下一行代码之前强制 View 重绘

matlab - 如何使用 MATLAB 消除视频中相机抖动造成的影响?

android - android.camera.NEW_PICTURE 在哪里定义的?

android-studio - Gradle是否包含在Android Studio中?

javascript - Facebook Graph API 我/ friend 没有返回任何内容

c# - 在Unity3d中使用Android陀螺仪,如何将初始相机旋转设置为初始移动设备旋转?

java - ImageLayoutBinding存在,ImageLayoutBindingImpl不存在,DataBinderMapperImpl在寻找impl文件。我怎样才能解决这个问题?

java - 如何向 Assets 中预填充的 sqlite 数据库添加新列或表并使用 SQLiteAssetHelper

java - 如何在android中获得支持的摄像机分辨率?

javascript - 如何存储从 Phonegap/Android 应用程序拍摄的照片