'https://www.b4x.com/android/forum/threads/class-send-e-mail-with-fileprovideruri.89217/#content
'añadir a manifes:
''E-Mail senden ab Android 6+
'AddManifestText(<uses-permission
' android:name="android.permission.WRITE_EXTERNAL_STORAGE"
' android:maxSdkVersion="18" />
')
'
'AddApplicationText(
' <provider
' android:name="android.support.v4.content.FileProvider"
' android:authorities="$PACKAGE$.provider"
' android:exported="false"
' android:grantUriPermissions="true">
' <meta-data
' android:name="android.support.FILE_PROVIDER_PATHS"
' android:resource="@xml/provider_paths"/>
' </provider>
')
'CreateResource(xml, provider_paths,
' <external-files-path name="name" path="" />
')
''Ende of File Provider
Sub Class_Globals
' Private rp As RuntimePermissions
Private GlobPath As String
Private GlobFileName As String
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub
Public Sub Send(Tipo As String ,Parte As String , Directorio As String, body As String, SendSub As String, Attachments As String, SendTo As String )
Dim SendAtt As String = ""
' Create Table Partes_Mails(IDRegistro bigint identity(1,1), Parte nvarchar(20), SendBody nvarchar(255), SendSub nvarchar(255), Adjuntos nvarchar(255),
' MailsDestino nvarchar(255), F_Envio DateTime Default GetDate(), Usuario int, Primary Key (IDRegistro))
'
'
'
' create procedure APP_MailEnviado(@Parte nvarchar(20), @SendBody nvarchar(255), @SendSub nvarchar(255), @Adjuntos nvarchar(255), @MailsDestino nvarchar(255),
' @Usuario int)
' As
' set nocount on
' Insert into Partes_Mails(Parte, SendBody, SendSub, Adjuntos, MailsDestino, Usuario)
' Values (@Parte, @SendBody, @SendSub, @Adjuntos, @MailsDestino, @Usuario)
'
Try
Dim Sql As String
Sql = "APP_MailEnviado ?,?,?,?,?,?,?"
Dim M As List
M.Initialize
M.Add(Tipo)
M.Add(Parte)
M.Add(body)
M.Add(SendSub)
M.Add(Attachments)
M.Add(SendTo)
M.Add(modGeneral.V_Usuario.Codigo)
modGeneral.clsConnec.Execute2(Sql,M,True)
Catch
Log(LastException)
MsgboxAsync(LastException.Message,"Cuando pueda , AVISE de esta incidencia: 'El MAIL no se guardó en la Base de Datos'. Gracias.")
End Try
GlobPath = Directorio
GlobFileName = Attachments
'Dim SendTo As String = "" '"myeMail@myDomain.com"
If Attachments <> "" Then
If GlobPath.ToLowerCase <> Starter.provider.SharedFolder.ToLowerCase Then
File.Copy(GlobPath, GlobFileName, Starter.provider.SharedFolder, GlobFileName) 'Put the file in a shared space ready for attaching
End If
SendAtt = File.Combine(GlobPath, GlobFileName)
End If
SendEmail (SendTo, body, SendSub, SendAtt )
End Sub
Private Sub SendEmail (SendTo As String, SendBody As String, SendSub As String, SendAtt As String)
Dim Linea As String
Try
Dim EmailIntent As Intent
Linea = "1"
'LogColor("Send Att: " & SendAtt, Colors.Red)
EmailIntent.Initialize(EmailIntent.ACTION_SEND, SendTo)
' EmailIntent.Initialize(EmailIntent.ACTION_SEND, Uri.fromParts(
' "mailto","abc@gmail.com", Null))
Dim LDestinos() As String
Linea = "10"
LDestinos = Regex.Split( ";",SendTo)
Linea = "20"
EmailIntent.SetType("text/plain") 'it is not related to the file itself.
Linea = "30"
EmailIntent.Flags = 1
Linea = "40"
If SendAtt <> "" Then
Linea = "100"
EmailIntent.PutExtra("android.intent.extra.STREAM", Starter.provider.GetFileUri(GlobFileName))
End If
Linea = "110"
EmailIntent.putExtra("android.intent.extra.SUBJECT", SendSub)
Linea = "120"
EmailIntent.putExtra("android.intent.extra.TEXT", SendBody)
Linea = "130"
EmailIntent.putExtra("android.intent.extra.EMAIL", LDestinos)
Linea = "200"
StartActivity (EmailIntent)
Linea = "300"
Catch
MsgboxAsync("Falló el envio del mail. Linea: " & Linea & CRLF & LastException.Message,"Error al enviar mail")
Log(LastException)
End Try
End Sub
Private Sub CreateFileProviderUri_deprecated (Dir As String, FileName As String) As Object
Dim FileProvider2 As JavaObject
Dim context As JavaObject
context.InitializeContext
FileProvider2.InitializeStatic("android.support.v4.content.FileProvider")
Dim f As JavaObject
f.InitializeNewInstance("java.io.File", Array(Dir, FileName))
Return FileProvider2.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))
End Sub