在Android中使用PhoneGap拾取图像/视频
如何在Android中使用PhoneGap拾取图像/视频(或拍照/视频)在Android中使用PhoneGap拾取图像/视频,android,cordova,Android,Cordova,如何在Android中使用PhoneGap拾取图像/视频(或拍照/视频) 我有一个web表单需要选择图像/视频内容并提交表单以上载内容。PhoneGap有能力这样做吗?或者我不得不回到原生Android代码?是的,您可以使用phonegap将图像上传到服务器 下面是选择图像或视频的代码 document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { pictureSou
我有一个web表单需要选择图像/视频内容并提交表单以上载内容。PhoneGap有能力这样做吗?或者我不得不回到原生Android代码?是的,您可以使用phonegap将图像上传到服务器 下面是选择图像或视频的代码
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}
function capturePhoto() {
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI });
}
function getPhoto(source) {
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
function onPhotoURISuccess(imageURI) {
// do whatever with imageURI
}
在html中,您必须编写
<button class="btn large" onclick="capturePhoto();">Capture Photo</button>
<button class="btn large" onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From
Photo Library</button>
即使是你也能经历这一切
但是谁可以将comera.MediaType与sourceType一起使用呢?
Camera.MediaType = {
PICTURE: 0, // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType
VIDEO: 1, // allow selection of video only, WILL ALWAYS RETURN FILE_URI
ALLMEDIA : 2 }