Android Question eMail, Attachments and Android 7 Crash

mw71

Active Member
Licensed User
Longtime User
Hi,

i use this Code to send a eMail with Attachment:
B4X:
Sub SendMail(varPhat As String, varDatei As String)

Dim Message As Email
Dim vSubject As String

vSubject= "LogFile: " & varDatei

'Message.To.Add("[email protected]")
Message.Subject = vSubject
Message.Body = ""
Message.Attachments.Add(File.Combine(varPhat, varDatei))

StartActivity(Message.GetIntent)

End Sub

worked well so far

now i become a crash Log:
android.os.FileUriExposedException: file:///storage/9016-4EF8/Android/data/.....File.adi exposed beyond app through ClipData.Item.getUri()

- The System with this error run with API 24/Android 7
- without the Attachment it works (the Starter Service Send successfull the CrashLog)
- Target SDK is 26
- on other (with Android 6 and below) it works fine

Is this a "File Provieder" Problem?
(https://www.b4x.com/android/forum/threads/sharing-files-from-your-app-with-file-provider.70458/)

What can I do to solve the problem?
 

mw71

Active Member
Licensed User
Longtime User
Hi,

thanks for replay! It works on my Test System.

Now i become a message from Firebase Crashlytics (from "Field"):
Caused by java.lang.IllegalArgumentException
Failed to find configured root that contains /storage/700C-19E1/Android/data/de.mypackage/files/20180523_202658.txt


android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile (FileProvider.java:738)
android.support.v4.content.FileProvider.getUriForFile (FileProvider.java:417)
java.lang.reflect.Method.invoke (Method.java)
anywheresoftware.b4j.object.JavaObject.RunMethod (JavaObject.java:131)
de.mypackage.main._createfileprovideruri (main.java:17314)
de.mypackage.main._sendmail (main.java:33327)


Code:
B4X:
Sub SendMail(varPhat As String, varDatei As String)
Starter.CL.Lg("Send eMail")

Dim vSubject As String
Dim Message As Email

vSubject= "LogFile: " & varDatei

'Message.To.Add("[email protected]")
Message.Subject = vSubject
Message.Body = ""


If p.SdkVersion >=24 Then
    Starter.CL.Lg("New")
    Message.Attachments.Add(CreateFileProviderUri(varPhat, varDatei))
Else
    Starter.CL.Lg("Old")
    Message.Attachments.Add(File.Combine(varPhat, varDatei))
End If

StartActivity(Message.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

The System with the Error run on Android 7

What can i do?, Thanks
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
yes, i am sure.

The User select source Database, Target Folder, Send by Mail (Checkbox)....,
the app read the Database and write the txt-File in a Service.
When Service finish an "Send by Mail" is checked, the Sub "SendMail" is called.
The time is to short for delete/move by User.


No, cant reproduce it.
On My System Android 7 (and below) it works.
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
its Match.

The selected Target Folder and generate File Name is passed to the
sub SendMail (selected Target Folder -> varPhat , generate File Name -> varDatei)
and forward by this to CreateFileProviderUri.
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
shared Folder means: rp.GetSafeDirDefaultExternal("") (in Starter Service) and
CreateResource(xml, provider_paths, <external-files-path name="name" path="" /> (in Manifest)??

I get the Phats with
B4X:
 Dim paths() As Object = GetContext.RunMethod("getExternalFilesDirs", Array(Null))

its the same as
B4X:
rp.GetAllSafeDirsExternal("")

(i think, when i show the results)
 
Last edited:
Upvote 0
Top