1

i am creating an phonegap application where user will capture some pictures and attach it to predefined mail id. Iam able to capture image but unable to attach all picture in app folder i.e "/mnt/sdcard/Android/data/pacakgename/cache/".

I tried to implement as in this for dynamic attachment.

My codes are below:

<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>

Any Help.

Community
  • 1
  • 1
surhidamatya
  • 2,419
  • 32
  • 56

1 Answers1

1

I got the solution for this. I was unable to understand fileDirectory api of phonegap that caused problem for me. I solved my problem with following code:

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);
                });

Now, we can pass attachFile to emailcomposer plugin:

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

I have solved it Please go through this link regarding my full answer. I posted my answer as i didn't wanted it to unsolved question. I used this emailcomposer plugin Hope, it may help someone.

Community
  • 1
  • 1
surhidamatya
  • 2,419
  • 32
  • 56
  • 1
    It's really awesome git link , now it's resolve my attachment text file problem and i can attach file & sent it successfully, thanks @sur007 – Ritesh Kumar Singh Sep 22 '14 at 11:25