My CodenameApp can export some data by sending it by e-mail, in the form of
json files.
This is the method:
public static void sendMyJsonFile(Form form,String fileName,String JSONText)
{
File file;
try {
file=new File("temp");
if (!file.exists()) file.mkdir();
File[] files=file.listFiles();
for (int i=0;i<files.length;i++)
{
files[i].delete();
}
file=new File("temp/"+fileName+".ext");
System.out.println("fileName "+file.getAbsolutePath());
OutputStream os =
Storage.getInstance().createOutputStream(file.getAbsolutePath());
os.write(JSONText.getBytes("UTF-8"));
os.flush();
os.close();
} catch (IOException e) {
return;
}
Message m = new Message("");
m.getAttachments().put(file.getAbsolutePath(), "text/plain");
System.out.println("attachments "+m.getAttachments().size());
getInstance().sendMessage(new String[] {""}, file.getName(), m);
}
A temp folder is created if it does not exist yet.
Then its content is deleted it it contains files.
The file is created and sent.
An alternate method version can use
file=new File(tempFolder,fileName+".ext");
but it is the same, please read the following:
I am testing it in the simulator and on Android device.
I can say that:
1-the file is not attached at all on Android and also on Windows10 (the
mail app opens and composes the message).
2-on the simulator the temp folder is created in .cn1\ but the files are
outside, so they are not deleted the next time the method is called.
Maybe it is also the reason for the file not being attached.
Paths seem to be correct.
log:
fileName file://home/temp/prova3.ext
attachments 1
sending message to <- this is not from my app
No errors are issued.
What's wrong?
Thanks in advance
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/57795eac-65eb-45f0-ae59-8d76a0970ac3n%40googlegroups.com.