1
如何在Android中使用PhoneGap選擇圖像/視頻(或拍攝照片/視頻)?在Android中使用PhoneGap選擇圖像/視頻
我有一個網絡表單需要選擇圖像/視頻內容並提交表單上傳內容。 PhoneGap能夠做到這一點嗎?或者我必須回退到原生Android代碼?
如何在Android中使用PhoneGap選擇圖像/視頻(或拍攝照片/視頻)?在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
但誰使用COmeara.MediaType與sourceType的? – Hunt