Android - Running endless code in Foreground while using the app
-
Im making an application that i want to have the ability to send report emails with a frequency. daily, weekly or monthly. Now i want those emails to be sent only if the app is running and if the user is using it (in my app you use the mobile as a kiosk, you open the app and leave it running all the time, screen will not close) I have write this code in the MainActivity where if someone has enabled the frequently email feature, the activity will try to send the email (SendStatisticsToEmailBySchedule() will run forever and will use SendStatisticsToEmail() from time to time to send an email):
public async void SendStatisticsToEmail(string subject, string address, int port, string from, string to, bool useSSL, bool saveDateSent = false, string username = "", string password = "", bool sendNowButtonUsed = false)
{
var fileName = System.IO.Path.Combine(
GetString(Resource.String.Statistics_ExportAllExportPrefix,
firstResult.ToString("MM-dd-yyyy"),
DateTime.Today.ToString("MM-dd-yyyy")));var message = new MimeMessage(); message.From.Add(new MailboxAddress(from)); message.To.Add(new MailboxAddress(to)); message.Subject = subject + " " + fileName; var statistics = new Statistics(); var reportsForXML = statistics.ConvertRecordsForExport(MyData); MemoryStream stream = new MemoryStream(); var builder = new BodyBuilder(); var image = BitmapFactory.DecodeResource(Resources, Resource.Drawable.get\_started); byte\[\] imgbyte; using (var bitmap = image) { var streamByte = new MemoryStream(); bitmap.Compress(Bitmap.CompressFormat.Png, 100, streamByte); bitmap.Recycle(); imgbyte = streamByte.ToArray(); } var imageAttach = builder.LinkedResources.Add(@"get\_started.png", imgbyte); imageAttach.ContentId = MimeUtils.GenerateMessageId(); builder.HtmlBody = string.Format(@"
{1}
{2}
{3}
", new object[] { imageAttach.ContentId, GetString(Resource.String.EmailExportSettings_MessageBodyLine1), GetString(Resource.String.EmailExportSettings_MessageBodyLine2), GetString(Resource.String.EmailExportSettings_MessageBodyLin
-
Im making an application that i want to have the ability to send report emails with a frequency. daily, weekly or monthly. Now i want those emails to be sent only if the app is running and if the user is using it (in my app you use the mobile as a kiosk, you open the app and leave it running all the time, screen will not close) I have write this code in the MainActivity where if someone has enabled the frequently email feature, the activity will try to send the email (SendStatisticsToEmailBySchedule() will run forever and will use SendStatisticsToEmail() from time to time to send an email):
public async void SendStatisticsToEmail(string subject, string address, int port, string from, string to, bool useSSL, bool saveDateSent = false, string username = "", string password = "", bool sendNowButtonUsed = false)
{
var fileName = System.IO.Path.Combine(
GetString(Resource.String.Statistics_ExportAllExportPrefix,
firstResult.ToString("MM-dd-yyyy"),
DateTime.Today.ToString("MM-dd-yyyy")));var message = new MimeMessage(); message.From.Add(new MailboxAddress(from)); message.To.Add(new MailboxAddress(to)); message.Subject = subject + " " + fileName; var statistics = new Statistics(); var reportsForXML = statistics.ConvertRecordsForExport(MyData); MemoryStream stream = new MemoryStream(); var builder = new BodyBuilder(); var image = BitmapFactory.DecodeResource(Resources, Resource.Drawable.get\_started); byte\[\] imgbyte; using (var bitmap = image) { var streamByte = new MemoryStream(); bitmap.Compress(Bitmap.CompressFormat.Png, 100, streamByte); bitmap.Recycle(); imgbyte = streamByte.ToArray(); } var imageAttach = builder.LinkedResources.Add(@"get\_started.png", imgbyte); imageAttach.ContentId = MimeUtils.GenerateMessageId(); builder.HtmlBody = string.Format(@"
{1}
{2}
{3}
", new object[] { imageAttach.ContentId, GetString(Resource.String.EmailExportSettings_MessageBodyLine1), GetString(Resource.String.EmailExportSettings_MessageBodyLine2), GetString(Resource.String.EmailExportSettings_MessageBodyLin
It is really nice that you wrote the message giving Thanks to the people here in CP. Pity is I had to kill it, due to the link. It would be considered site driving and it is not allowed. Please write the message again without the link and it will get through.
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
It is really nice that you wrote the message giving Thanks to the people here in CP. Pity is I had to kill it, due to the link. It would be considered site driving and it is not allowed. Please write the message again without the link and it will get through.
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.