如何在Android中使用PhoneGap选择图像/视频(或拍摄照片/视频)?
我有一个网页表单需要选择图像/视频内容并提交表单以上传内容。 PhoneGap能够这样做吗?或者我必须回归本机Android代码?
答案 0 :(得分:3)
是的,您可以使用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>
视频
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 }
即使你可以通过这个
http://docs.phonegap.com/en/1.4.0/phonegap_camera_camera.md.html#Camera