Hi everyone, I'm trying to send an email from my app, but it gives me an error (at this line: StartActivity (EmailIntent)) in the class line "SendEmail", here is the code
here's the mistake:
Send Att: /storage/emulated/0/lavori/fg dfg 19-1-2020 7:35:38.txt
Error occurred on line: 43 (clsSendMail)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=[email protected] typ=text/plain flg=0x20001 clip={text/plain T:eccoti i dati da caricare} (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2576)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:2229)
at android.app.Activity.startActivityForResult(Activity.java:4286)
at android.app.Activity.startActivityForResult(Activity.java:4244)
at android.app.Activity.startActivity(Activity.java:4583)
at android.app.Activity.startActivity(Activity.java:4551)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:848)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:780)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:363)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
What can I do? thank you
B4X:
Sub Class_Globals
Private rp As RuntimePermissions
Private shared As String
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
shared = rp.GetSafeDirDefaultExternal("")
End Sub
Public Sub Send(dir As String, body As String, SendSub As String, Attachments As String)
Dim SendAtt As String = ""
GlobPath = dir
GlobFileName = Attachments
Dim SendTo As String = "[email protected]" '"[email protected]"
If Attachments <> "" Then
File.Copy(GlobPath, GlobFileName, shared, GlobFileName) 'Put the file in a shared space ready for attaching
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 EmailIntent As Intent
LogColor("Send Att: " & SendAtt, Colors.Red)
EmailIntent.Initialize(EmailIntent.ACTION_SEND, SendTo)
EmailIntent.putExtra("android.intent.extra.SUBJECT", SendSub)
EmailIntent.putExtra("android.intent.extra.TEXT", SendBody)
EmailIntent.SetType("text/plain") 'it is not related to the file itself.
EmailIntent.Flags = 1
If SendAtt <> "" Then
EmailIntent.PutExtra("android.intent.extra.STREAM", CreateFileProviderUri(shared, GlobFileName))
End If
StartActivity (EmailIntent)
End Sub
Private 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
here's the mistake:
Send Att: /storage/emulated/0/lavori/fg dfg 19-1-2020 7:35:38.txt
Error occurred on line: 43 (clsSendMail)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=[email protected] typ=text/plain flg=0x20001 clip={text/plain T:eccoti i dati da caricare} (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2576)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:2229)
at android.app.Activity.startActivityForResult(Activity.java:4286)
at android.app.Activity.startActivityForResult(Activity.java:4244)
at android.app.Activity.startActivity(Activity.java:4583)
at android.app.Activity.startActivity(Activity.java:4551)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:848)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:780)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:363)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
What can I do? thank you