问题
How can I pick an image / video ( or take a photo / video ) using PhoneGap in Android ?
I have a web form needs to pick image / video contents and submit the form to upload the contents. Is PhoneGap capable to do so? or I have to fall back to native Android codes?
回答1:
Yes you can upload image to server with phonegap
Here is the code to pick image or video
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
}
in html you have to write
<button class="btn large" onclick="capturePhoto();">Capture Photo</button>
<button class="btn large" onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From
Photo Library</button>
for video
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 }
even you can go through this
http://docs.phonegap.com/en/1.4.0/phonegap_camera_camera.md.html#Camera
来源:https://stackoverflow.com/questions/13116063/pick-an-image-video-using-phonegap-in-android