Android Question Send an email(SOLVED)

Stichler

Active Member
Licensed User
Hi,
Maybe I missed something like a library or something, but here is the code, and the error I receive. Any help?

B4X:
Dim Message As Email
    Message.To.Add(Var.parentsemail)
    Message.Attachments.Add(File.Combine(File.DirInternal, "letter.txt"))
    StartActivity(Message.GetIntent)

Copying updated assets files (2)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (write) Create, isFirst = true **
** Activity (write) Resume **
Error occurred on line: 120 (Write)
android.os.FileUriExposedException: file:///data/user/0/cma.lettertosanta/files/letter.txt exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
at android.net.Uri.checkFileUriExposed(Uri.java:2356)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:944)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10480)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10465)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
at android.app.Activity.startActivityForResult(Activity.java:4564)
at android.app.Activity.startActivityForResult(Activity.java:4522)
at android.app.Activity.startActivity(Activity.java:4883)
at android.app.Activity.startActivity(Activity.java:4851)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:848)
at cma.lettertosanta.write._btnsend_click(write.java:582)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:738)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
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:6891)
at android.widget.TextView.performClick(TextView.java:12651)
at android.view.View$PerformClick.run(View.java:26083)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 

Josias

Member
Licensed User
Longtime User
This works perfectly for me:

Dim emlMsg As Email
emlMsg.To.Add("peter@gmail.com")
emlMsg.CC.Add("peter@gmail.com")
emlMsg.Subject = "Registration"
emlMsg.Body = "Some text "
'emlMsg.Attachments.Add(File.Combine(File.DirRootExternal, "SomeFile.txt"))
StartActivity(emlMsg.GetIntent)

Don't forget to include Phone library
 
Upvote 0
Top