Hi guys,
I got an error when using email with attachment. B4A 8.30, device Oreo 8.0, phone library version 2.5.
Here is codes in Main
Codes in Starter
Codes in activity that send mail
Codes in manifest editor
On Oreo 8.0, when Sub SendMail called, file test.bok created in root external folder,then app just quit.
Log file error : java.lang.reflect.InvocationTargetException
Any hints how to fix this problem?
Thanks in advance.
I got an error when using email with attachment. B4A 8.30, device Oreo 8.0, phone library version 2.5.
Here is codes in Main
B4X:
Process Global
Public PUB_InstDir as String
End Sub
Codes in Starter
B4X:
Sub Process_Globals
Public rp As RuntimePermissions
End Sub
Sub Service_Create
Main.PUB_InstDir= rp.GetSafeDirDefaultExternal("")
End Sub
Codes in activity that send mail
B4X:
Sub SendMail
File.Copy(Main.PUB_InstDir,"myfile.hny",File.DirRootExternal,"test.bok")
Private Msg As Email
Private p As Phone
If p.SdkVersion >=24 Then
Msg.Attachments.Add(CreateFileProviderUri(Main.PUB_InstDir,"myfile.hny"))
Else
Msg.Attachments.Add(File.Combine(Main.PUB_InstDir,"myfile.hny"))
End If
Msg.To.Add("test@gmail.com")
Msg.Subject = "Mail Subject "
Msg.Body = "Mail Body"
StartActivity(Msg.GetIntent)
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
Codes in manifest editor
B4X:
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="" />
)
On Oreo 8.0, when Sub SendMail called, file test.bok created in root external folder,then app just quit.
Log file error : java.lang.reflect.InvocationTargetException
Any hints how to fix this problem?
Thanks in advance.
Last edited: