简体   繁体   English

如何在Android应用上访问相机onclick?

[英]How to access camera onclick on Android app?

I am currently using Visual Studio to work on my project, and i need a function which allows the opening of camera on the press of a button. 我目前正在使用Visual Studio来处理我的项目,我需要一个允许按下按钮打开相机的功能。 I have some codes from a previous project but they don't seem to work now. 我有一些来自之前项目的代码,但它们现在似乎不起作用。 Below are my codes. 以下是我的代码。

js: 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: 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 :)">

Please advise & let me know if there's anything else you need to know! 如果您还需要了解其他信息,请告知我们并告诉我们! Thank you all! 谢谢你们!

For access to mobile phone camera for getting photo or video in android or ios you can simply use input[type="file"] like this: 要访问手机摄像头以获取androidios photovideo ,您只需使用input[type="file"]如下所示:

Getting photo: 获取照片:

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

Getting video: 获取视频:

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

For opening back camera: 用于打开后置摄像头:

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

And for selfie camera (front): 而对于自拍相机(前):

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

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在电子应用程序内访问摄像机/网络摄像机? - How to access camera/webcamera inside electron app? 如何通过网络应用访问我的安卓智能手机的前后摄像头? - How can I access my android smartphone's both front and rear camera through a web app? 如何在 Android WebView 中允许访问相机 - How to allow access to camera in Android WebView HTML5 / javascript Android应用程序可以访问摄像机/录音机吗? - Can an HTML5/javascript Android app access the camera/voice recorder? 装有Android 6.0.1的Nexus 7上的Cordova相机访问崩溃应用 - Cordova Camera access crash app on Nexus 7 with Android 6.0.1 如何在onclick函数中访问变量以进行角度的应用内浏览? - How to access variables in onclick function for in-app browsing in angular? 如何在 iOS11 主屏幕 Web 应用程序上访问相机? - How to access camera on iOS11 home screen web app? 如何在反应原生 expo 中访问相机应用程序中拍摄的照片? - How to access photos taken within a camera app in react native expo? 安卓工作室。 如何访问 OnClick 方法中的另一个按钮? - Android Studio. How to access another button in a OnClick method? 如何从android应用程序的webview访问设备摄像头 - how to access the device camera from webview of android application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM