Android Question Email intent problem.

robh

Member
Licensed User
Longtime User
I have my application used by 4 users, all using the same device model on the same version of android. As part of the application a user can submit an order and generate an order acknowledgment email. During the creation of the email I have 2 users experiencing major issues and 2 users who have not experienced a problem in 12 months of use. The code structure is basically as follows.


Build string variable up some html content(a table containing rows with the order detail)
Check if 'acknowledgements' directory exists in the defaultexternal directory and create if not.
Use File.writestring to dump the string contents to a new file <xxxxxx>.html in above directory where xxxxxx is the ordernumber.
Then using Email library, add recipient, subject and body and attach above file and call StartActivity(email.getintent)

What I am seeing is that randomly on some orders, 2 of the 4 users are having to wait up to 1 hour for the email client to start up with email and it's attachment. I can only think that the problem is perhaps related to File.writestring not closing the file which results in the Email struggling to attach the file just created. Can anybody advise on the issue or potential cause if I'm barking up the wrong tree. Would there be any benefit in me using file.textwriter where I can actually code in a flush and close prior to calling the email intent, thus ensuring the file is definitely closed? I would have thought the file.writestring would have been taking care of this which is why I haven't tried my own suggestion as yet. I can't re-create the problem on my own tablet(same model as 4 users) and the 2 affected users are only experiencing this randomly but as this is a business based system that is used in front of clients it is vital that I resolve this issue or at least have an idea as to why the operating system is causing such a delay with a simple and very small email.

many thanks in advance.
 

robh

Member
Licensed User
Longtime User
File.WriteString uses a TextWriter to write the string and it then closes the file. The issue is somewhere else.
Probably with the mail app itself.

You can switch to SMTP from the Net library instead. It will allow you to directly send the mail.
Hi Erel,

Thanks for your response, I pretty much thought the WriteString was a wrapper for the textwriter so didn't bother implementing the change. We have experienced the same issues over the weekend, 2 users suffering problems and 2 were fine, all running Samsung Note 10.1 tablets, all same OS version all using the default email client with the same settings, I've been scratching my head with this one for a month now.

Could it be possible that it's something to do with the amount of files in the application cache directory as we store other files in there as part of another module within the application. i.e. when the application attempts to write out the text file, there is not enough space in the cache directory so it has to spend some time deleting files it deems are to be removed in order to free up space? Sorry, I'm clutching at straws I know but I'm at a loss as to which direction to go now?

I'll have a look at the SMTP method but I' would need to speak to our network admin as I'm not sure about possible security implications and access to directly send mail unsing our exchange server as a relay. The preferred method is to use the email client so it's all in the users control.

If you can suggest anything else to look into it would be most appreciated. Is there anyway of constructing the attachment in memoryand attaching it as some form of binary object that's passed to the mail client without having to stream out to a file first as I'm sure the problem surrounds this area.

Many thanks
 
Upvote 0

robh

Member
Licensed User
Longtime User
I'm pretty sure that it has nothing to do with saving the file but rather with the mail app. Are you able to reproduce this issue when connected to the IDE?
Unfortunately, I'm unable to produce this in the IDE or on my own tablet.
 
Upvote 0

robh

Member
Licensed User
Longtime User
Yes Erel you are correct, I would usually just dismiss this as something the user was doing that's strange or a bug in code however I have 2 users reporting exactly the same issue which unfortunately I can't replicate.
Yes, over this weekend the user has reported the following.
Submitted the first order and it took 15 minutes at which point he gave up and rebooted the tablet. He then submitted a second order, the email took 3 minutes to pop up. He then rebooted again (it seems to improve with a reboot) and placed a 3 order and again 3 minute delay for email to appear. Finally reboot and 4th order, same result, 3 minutes to pop up.

As you say, all very strange indeed.

I have included my email method below if that sheds any light on the subject? Again, thanks for all your replies and sorry if it seems I'm wasting your time.



B4X:
Sub SendMail(SendTo As String, SendBody As String, SendSub As String, SendAtt As String)   
    Dim message As Email   
    SendTo = SendTo.Trim   
    message.To.Add(SendTo)   
    message.Body = SendBody   
    message.Subject = SendSub.Trim   
   
    If SendAtt <> "" Then       
        message.Attachments.Add(SendAtt)   
    End If   
   
    Try       
        StartActivity(message.GetIntent) 
       
    Catch       
        Msgbox("Email Client Could Not Be Accessed, Please Make Sure You Have Setup Your Email Client", "NOTICE")   
    End Try
   
End Sub
 
Upvote 0
Top