我可以在网络视图中打开相机吗?

发布于 2024-11-03 21:56:03 字数 32 浏览 3 评论 0原文

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

Can I open android camera in webview?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空心空情空意 2024-11-10 21:56:03

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

如果您使用 API,则必须自己构建大量 UI。这是好是坏取决于您需要在应用程序中执行什么操作以及您需要对“拍照过程”进行多少控制。如果您只需要一种快速拍摄照片并在应用程序中使用它的方法,那么 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,然后将其发布到我的服务器。但是,这可能比您需要知道的更多。 :)

这里是制作它的链接在 webView 上工作

The easiest way to have the camera functionality when using a Webview would be the use an 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.

Intent Example:

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.

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

here is the link to make it work on webView

花辞树 2024-11-10 21:56:03

据我所知,这并不是直接内置于 Android API 中的。但是,您可以使用 PhoneGap,它提供了与本机设备功能(即相机)的 Javascript 挂钩。

您可以在此处查看支持的功能列表,并阅读其相机 API 文档此处

As far as I know this isn't built into the Android API directly. However, you can use PhoneGap, which provides Javascript hooks into native device functionality (i.e., the camera).

You can view a list of supported features here, and read their Camera API documentation here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文