如何在 Android 中使用 PhoneGap 选择图像/视频(或拍摄照片/视频)?
我有一个网络表单需要选择图像/视频内容并提交表单以上传内容。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>
用于视频
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