Pick an image / video using PhoneGap in Android

夙愿已清 提交于 2020-01-30 08:22:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!