javascript - 如何在 Android 应用程序上访问相机 onclick?

标签 javascript android html

我目前正在使用 Visual Studio 处理我的项目,我需要一个允许按下按钮打开相机的功能。我有一些以前项目的代码,但它们现在似乎不起作用。以下是我的代码。

js:

function getImage() {
    // Retrieve image file location from specified source
    navigator.camera.getPicture(uploadPhoto,
        function (message) { alert('get picture failed'); },
        { quality: 10, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY }
    );
}

HTML:

<form id="buyforme">

<img id="myimg" height="100">
<input type="button" name="selectimg" id="selectimg" onclick="getImage();" value="Take a picture of this item :)">

如果您还有其他需要知道的,请告知并告诉我!谢谢大家!

最佳答案

要在androidios 中访问手机相机以获取照片视频,您可以简单地使用输入[type="file"] 像这样:

获取照片:

 <input type="file" accept="image/*" capture="camera">

获取视频:

<input type="file" name="video" accept="video/*" capture="environment">

打开后置摄像头:

<input type="file" name="image" accept="image/*" capture="environment">

自拍相机(正面):

<input type="file" name="image" accept="image/*" capture="user">

Source

关于javascript - 如何在 Android 应用程序上访问相机 onclick?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47325356/

相关文章:

javascript - 嵌入的 js 文件不适用于 jQuery .load() 内容

html - 响应式布局和列 float 问题

android - 隐藏 AppBarLayout 并将其空间留给剩余的 View

android - Jetpack 撰写内部编译器参数警告

java - Android 从计时器任务启动 Activity

html - 在链接中定位图像

javascript - 将连续的 ","合并为单个 ","并在一个 RegExp 中删除前导和尾随 ","

javascript - React Stepzilla 中的 React 路由器

javascript - 仅使用 Angular-Material 切换 sidenav?

javascript - 如何将超链接插入 Javascript 随机文本数组?