Android PhoneGap转换-HTML到.apk

Android PhoneGap转换-HTML到.apk,android,cordova,camera,Android,Cordova,Camera,我正在用我的文件选择器将一个HTML应用程序转换成一个.apk,一切都很好 <input name="file" type="file" id="file"> 我希望能够从相机和文件系统中仅选择图像(如果它可以选择更多,这并不重要,但它是我正在寻找的图像) 在web版本中,这在我的手机上非常有效,但当转换为.apk时,此功能将丢失,我似乎无法在此处或在线找到与此问题相关的任何内容。至少对我来说,输入文件在Phonegap中不起作用 您需要使用Phonegap API获取图片并选

我正在用我的文件选择器将一个HTML应用程序转换成一个.apk,一切都很好

<input name="file" type="file" id="file">

我希望能够从相机和文件系统中仅选择图像(如果它可以选择更多,这并不重要,但它是我正在寻找的图像)


在web版本中,这在我的手机上非常有效,但当转换为.apk时,此功能将丢失,我似乎无法在此处或在线找到与此问题相关的任何内容。

至少对我来说,输入文件在Phonegap中不起作用

您需要使用Phonegap API获取图片并选择来源,如photolibrary、camera或savedphotoalbum

查看有关camera.getPicture的更多信息:
关于cameraOptions方法的Camera.PictureSourceType参数:

最终使用子浏览器系统,如下所示

在头上

<script src="childbrowser.js"></script>
<script type="text/javascript" charset="utf-8" src="json2.js"></script>
<script type="text/javascript" charset="utf-8">

// Called when capture operation is finished
//
function captureSuccess(mediaFiles) {
    var i, len;
    for (i = 0, len = mediaFiles.length; i < len; i += 1) {
        uploadFile(mediaFiles[i]);
    }       
}

// Called if something bad happens.
// 
function captureError(error) {
    var msg = 'An error occurred during capture: ' + error.code;
    navigator.notification.alert(msg, null, 'Uh oh!');
}

// A button will call this function
//
function captureImage() {
    // Launch device camera application, 
    // allowing user to capture up to 2 images
    navigator.device.capture.captureImage(captureSuccess, captureError, {limit: 2});
}

// Upload files to server
function uploadFile(mediaFile) {
    var ft = new FileTransfer(),
        path = mediaFile.fullPath,
        name = mediaFile.name;

    ft.upload(path,
        "http://my.domain.com/upload.php",
        function(result) {
            console.log('Upload success: ' + result.responseCode);
            console.log(result.bytesSent + ' bytes sent');
        },
        function(error) {
            console.log('Error uploading file ' + path + ': ' + error.code);
        },
        { fileName: name });   
}

</script>

体内

<button class="button-big"     onClick="window.plugins.childBrowser.showWebPage('URL_TO_GO_HERE',
                                    { showAddress: false });" style="width: 100%;">UPLOAD     PHOTOS</button>
<input type="button" class="button-big" style="width: 100%;" onclick="captureImage();" value="TAKE PHOTO">
上传照片
它有一个标准的文件上传程序,比如

<input name="file" type="file" id="file">

然后让我从根存储中进行选择,在phonegap 2.2之后的iOS和Android操作系统中都可以使用

为了拍摄一张照片,我在脑袋里用了这个

<script src="childbrowser.js"></script>
<script type="text/javascript" charset="utf-8" src="json2.js"></script>
<script type="text/javascript" charset="utf-8">

// Called when capture operation is finished
//
function captureSuccess(mediaFiles) {
    var i, len;
    for (i = 0, len = mediaFiles.length; i < len; i += 1) {
        uploadFile(mediaFiles[i]);
    }       
}

// Called if something bad happens.
// 
function captureError(error) {
    var msg = 'An error occurred during capture: ' + error.code;
    navigator.notification.alert(msg, null, 'Uh oh!');
}

// A button will call this function
//
function captureImage() {
    // Launch device camera application, 
    // allowing user to capture up to 2 images
    navigator.device.capture.captureImage(captureSuccess, captureError, {limit: 2});
}

// Upload files to server
function uploadFile(mediaFile) {
    var ft = new FileTransfer(),
        path = mediaFile.fullPath,
        name = mediaFile.name;

    ft.upload(path,
        "http://my.domain.com/upload.php",
        function(result) {
            console.log('Upload success: ' + result.responseCode);
            console.log(result.bytesSent + ' bytes sent');
        },
        function(error) {
            console.log('Error uploading file ' + path + ': ' + error.code);
        },
        { fileName: name });   
}

</script>

//捕获操作完成时调用
//
函数CaptureSucture(媒体文件){
变量i,len;
对于(i=0,len=mediaFiles.length;i
这个在身体里

<button class="button-big"     onClick="window.plugins.childBrowser.showWebPage('URL_TO_GO_HERE',
                                    { showAddress: false });" style="width: 100%;">UPLOAD     PHOTOS</button>
<input type="button" class="button-big" style="width: 100%;" onclick="captureImage();" value="TAKE PHOTO">

复制和过去,它就像一个梦

在这张图片中查看它

任何问题,只要发邮件评论


或者给我发电子邮件。。。support@carbonyzed.co.uk

正确,带有文件类型的输入在Android上不起作用。它不适用于大多数移动浏览器。如果您只想获取图片,那么应该使用带有PHOTOLIBRARY选项的camera.getPicture()。