2012-10-29 30 views
1

如何在Android中使用PhoneGap选择图像/视频(或拍摄照片/视频)?在Android中使用PhoneGap选择图像/视频

我有一个网络表单需要选择图像/视频内容并提交表单上传内容。 PhoneGap能够做到这一点吗?或者我必须回退到原生Android代码?

回答

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

+0

但谁使用COmeara.MediaType与sourceType的? – Hunt