1

我正在创建一个 phonegap 应用程序,用户将在其中捕获一些图片并将其附加到预定义的邮件 ID。我能够捕获图像但无法附加应用程序文件夹中的所有图片,即“/mnt/sdcard/Android/data/pacakgename/cache/”。

我试图在实现动态附件。

我的代码如下:

<html>
<head>
    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8" src="emailcomposer.js"></script>

    <script type="text/javascript">
    document.addEventListener("deviceready", deviceready, true);
    function deviceready() {
        console.log("Device ready");    
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, onFail);
    }

function gotFS(fileSystem) {
var reader = fileSystem.root.createReader();
reader.readEntries(gotList, onFail);
}

function gotList(entries) {
var i;
var fullPath = "/mnt/sdcard/Android/data/packagename/cache/";
for (i=0; i<entries.length; i++) {
    if (entries[i].name.indexOf(".jpg") != -1) {
        console(entries[i].fullPath);
    }
}
}

    function composeText(){
    var message1 = document.getElementById('message_body').value;
    console.log(message1);
    window.plugins.emailComposer.showEmailComposer(
            "Get an Estimate",
            message1,
            ["sth@mail.com"],
            [],
            [],
            true,
            [attachment link]
        );
    //exit the app after clicking this button
    navigator.app.exitApp();
    // navigator.camera.cleanup(onSuccess,fail);
    // function onSuccess(){

    // }

    // function fail(){

    // }

    }

    function onFail(message) {
  alert('Failed because: ' + message);
}

    </script>
    <style type="text/css">
li{
list-style: none;
float:left;
padding: 0 5 5 0 ;
}
    </style>
</head>
<body>
    <h1>Get a Repair Estimate</h1>

<div style="clear:both;"></div>
Provide any details you want us to know(Optional):
<ul>
    <li>
<textarea style="width:250px;height:250px;" name="message_body" id = 'message_body'  placeholder="Add Notes here(if any)"></textarea>
</li>
<div style="clear:both;"></div>
<li>

      <button onclick="composeText();">Get Your Estimate</button>
    </li>
</body>
</html>

任何帮助。

4

1 回答 1

1

我得到了解决方案。我无法理解对我造成问题的 phonegap 的 fileDirectory api。我用以下代码解决了我的问题:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
                    fileSystem.root.getDirectory("MyAppFolder", {
                        create: true
                    }, 
        function(directory) {
            console.log("Final 63" + directory.fullPath);
            attachPaths = directory.fullPath;
            var attachPath=attachPaths.slice(7,attachPaths.length);
            var directoryReader = directory.createReader();
            directoryReader.readEntries(function(entries) {
                var i;
                for (i=0; i<entries.length; i++) {
                    console.log(entries[i].name);
attachFile[i] =attachPath + "/" + entries[i].name;
                            }
                            console.log(attachFile);
                        }, 
                        function (error) {
                            alert(error.code);
                        });

                    });
                }, function(error) {
                    alert("can't even get the file system: " + error.code);
                });

现在,我们可以将 attachFile 传递给 emailcomposer 插件:

window.plugins.emailComposer.showEmailComposerWithCallback(null,
                    "Get an Estimate",
                     "Here is the mail body"
                    ["to"],
                    [cc],
                    [bcc],
                    true,
                    attachFile
                    );

我已经解决了请通过此链接了解我的完整答案。我发布了我的答案,因为我不希望它成为未解决的问题。我使用了这个emailcomposer 插件 希望,它可以帮助某人。

于 2013-10-03T04:10:52.407 回答