Sub Globals
Dim email As Email
End Sub
Sub CreateFileProviderUri (Dir As String, FileName As String) As Object
Dim FileProvider As JavaObject
Dim context As JavaObject
context.InitializeContext
FileProvider.InitializeStatic("android.support.v4.content.FileProvider")
Dim f As JavaObject
f.InitializeNewInstance("java.io.File", Array(Dir, FileName))
Return FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))
End Sub
Sub ForceMediaScan(dir As String, filename As String)
Dim Phone As Phone
Dim i As Intent
i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", "content://" & File.Combine(dir, filename))
Phone.SendBroadcastIntent(i)
End Sub
Sub SendNewMail
File.Copy(Path1, GlobFileName, Starter.shared, GlobFileName) 'Put the file in a shared space ready for attaching
Dim SendTo As String = Starter.kvs.Get("FaveMail")
Dim SendBody As String = "Please prepare this script and contact me once it is complete and ready for delivery or collection."&CRLF&CRLF&"I do understand that I can only receive my medication on presentation of the original script"
Dim SendSub As String = "New Script for: "&Starter.kvs.get("UserName")&" - "&Starter.kvs.get("IdNumber")
SendEmail (SendTo, SendBody, SendSub, File.Combine(Starter.shared, GlobFileName ))
End Sub
Sub SendEmail (SendTo As String, SendBody As String, SendSub As String, SendAtt As String)
Dim FinalEmailIntent As Intent, sPackageName As String
LogColor("Send Att: "&SendAtt,Colors.Magenta)
If SendAtt = "" Then ' Use new method - will not work with attachments
File.Copy(Path1, GlobFileName, Starter.shared, GlobFileName)
Log("11111")
FinalEmailIntent.Initialize("android.intent.action.SENDTO", "mailto:" & SendTo)
FinalEmailIntent.putExtra("android.intent.extra.SUBJECT", SendSub)
FinalEmailIntent.putExtra("android.intent.extra.TEXT", SendBody)
FinalEmailIntent.PutExtra("android.intent.category.DEFAULT", CreateFileProviderUri(Starter.shared, GlobFileName))
FinalEmailIntent.Flags = 1
FinalEmailIntent.WrapAsIntentChooser("Send E-mail")
Else ' Make our own list of email apps
Log("22222")
sPackageName = GetEmailPackage
If sPackageName = "/cancel/" Then Return
If sPackageName = "" Then
Msgbox ("Unable to send email.", "")
Return
End If
Log("33333")
Dim MyEmail As Email
MyEmail.To.Add (SendTo)
MyEmail.Body = SendBody
MyEmail.Subject = SendSub
MyEmail.Attachments.Add(SendAtt)
FinalEmailIntent = MyEmail.GetIntent
FinalEmailIntent.SetComponent (sPackageName)
End If
StartActivity (FinalEmailIntent)
End Sub
Sub GetEmailPackage As String
Dim PM As PackageManager, DummyIntent As Intent, DummyIntent2 As Intent
Dim EmailActivities As List, EmailAppNames As List, iPackage As Int, x As Int, tempString As String
EmailActivities.Initialize: EmailAppNames.Initialize
DummyIntent.Initialize("android.intent.action.SENDTO", "mailto:[email protected]")
EmailActivities = PM.QueryIntentActivities (DummyIntent)
If EmailActivities.Size = 0 Then
DummyIntent2.Initialize("android.intent.action.SENDMULTIPLE", "")
DummyIntent2.SetType ("message/rfc822")
EmailActivities = PM.QueryIntentActivities (DummyIntent2)
End If
If EmailActivities.Size = 0 Then Return ""
' Get app labels & icons
For x = 0 To EmailActivities.Size - 1
Dim imgIcon As BitmapDrawable
Dim sPackageName As String = EmailActivities.Get(x)
sPackageName = sPackageName.SubString2 (0, sPackageName.IndexOf ("/"))
tempString = PM.GetApplicationLabel(sPackageName)
imgIcon = PM.GetApplicationIcon(sPackageName) 'App icon if desired
EmailAppNames.Add (tempString)
Next
iPackage = InputList (EmailAppNames,"Send email using",-1)
If iPackage = DialogResponse.CANCEL Then Return "/cancel/"
Return EmailActivities.Get (iPackage)
End Sub