我可以在web视图打开相机? [英] Can I open camera in webview?

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

问题描述

我可以在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. :)

<一个href="http://androidexample.com/Open_File_Chooser_With_Camera_Option_In_Webview_File_Option/index.php?view=article_discription&aid=128&aaid=148"相对=nofollow>这里是让web视图上工作的链接

here is the link to make it work on webView

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

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