我可以在 webview 中打开相机吗? [英] Can I open camera in webview?

查看:35
本文介绍了我可以在 webview 中打开相机吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 webview 中打开安卓相机吗?

Can I open android camera in webview?

推荐答案

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

The easiest way to have the camera functionality when using a Webview would be the use an Intent.

如果您使用 API,您必须自己构建很多 UI.这是好是坏取决于您需要在应用程序中做什么以及您需要对拍照过程"进行多少控制.如果您只需要一种快速拍摄照片并在您的应用程序中使用它的方法,那么 Intent 是您的最佳选择.

If you use the API you have to build a lot of the UI yourself. This is good or bad depending on what you need to do in your application and how much control you need over the "picture taking process". If you just need a quick way to snap a photo and use it in your application, Intent is the way to go.

意图示例:

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.
            }
}

我从另一个答案中借用了这个例子的一部分来最初构建它.但是我没有网址了.

I borrowed parts of this example from another answer to build this originally. But I don't have the URL anymore.

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

In the app I am writing now, I convert this image to Base64 and then pass it to Javascript which then posts it to my server. But, that's probably more than you needed to know. :)

这里是制作链接它适用于 webView

here is the link to make it work on webView

这篇关于我可以在 webview 中打开相机吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆