gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:33:55 26 4
gpt4 key购买 nike

我可以在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com