我可以在web视图打开相机?视图、相机、web

2023-09-06 02:33:14 作者:旧梦多故人﹌ ▼

我可以在web视图打开Android相机?

Can I open android camera in webview?

推荐答案

有相机功能时,使用web视图将是使用意图的最简单方法。

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

如果您使用的API,你必须建立大量的UI自己。这是好是坏取决于你需要做的,你的应用程序和多少控制,你需要在拍照的过程。如果你只需要一个快速的方法来拍摄照片,并用它在你的应用程序,意图是要走的路。

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,然后把它传递给Java脚本,然后张贴到我的服务器。但是,这不是你需要知道的可能更多。 :)

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. :)

这里是让web视图上工作的链接

here is the link to make it work on webView