Android Question sedm mail error

powerino

Active Member
Licensed User
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
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
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You should test such features with a Real device.

Is there a configured email app installed on the Bluestack?
 
Upvote 0

powerino

Active Member
Licensed User
With a real device i have this error:

*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
ExecuteMemoryTable: SELECT * FROM LavoroTB
Error occurred on line: 158 (Main)
java.io.FileNotFoundException: /storage/emulated/0/lavori/s itg 19-1-2020 11:45:29.txt (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:231)
at java.io.FileInputStream.<init>(FileInputStream.java:165)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:214)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:340)
at com.guerrinosantoni.artigiano.main._btncreafile_click(main.java:562)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
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)
at android.view.View.performClick(View.java:6603)
at android.view.View.performClickInternal(View.java:6576)
at android.view.View.access$3100(View.java:780)
at android.view.View$PerformClick.run(View.java:26089)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6702)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
** Activity (main) Pause, UserClosed = true **
 
Upvote 0
Top