Storage works. I was talking about the File API vs. FileSystemStorage. The
latter has a get app home directory which is a specific special case for
external intents. I suggest using that. Look in the Javadoc samples where
this approach is used.
On Thursday, February 11, 2021 at 12:18:26 PM UTC+2 P5music wrote:
> It is the same also without putting the file in the "temp" folder under
> the private home directory.
> And
> file name are created like file__home_filename.
> I also prefixed the file name with "file__home_" but always the attachment
> is null, the fileUrl field is empty, and also mimetype is wrong because it
> is like image, if I look into it at debug.
> Is this an issue in
> Message.getAttachments().put();
> ?
> And with
> "I suggest you use FileSystemStorage and save the files to the app home
> directory which is a special case on Android"
> are you saying that, as a matter of fact, Storage does not work on Android?
>
> Il giorno giovedì 11 febbraio 2021 alle 03:59:33 UTC+1 Shai Almog ha
> scritto:
>
>> I suggest you use FileSystemStorage and save the files to the app home
>> directory which is a special case on Android. Things like attachments etc.
>> Work better when they're stored in the app home folder.
>>
>> On Wednesday, February 10, 2021 at 7:24:01 PM UTC+2 P5music wrote:
>>
>>> 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/b9bbbabf-c260-4de1-948a-35ba5901f3e6n%40googlegroups.com.