It seems these issues keep popping up, and the previous fix no longer works.
I am trying to email a file from a B4A app.
I am getting the following permissions:
PERMISSION_READ_EXTERNAL_STORAGE,
PERMISSION_WRITE_EXTERNAL_STORAGE
This is the code I am using, along with the FileProvider class:
In Starter:
In Main:
In the activity:
The app crashes exactly on the ei.Attachments.Add statement with:
Line 34 of the FileProvider class is:
As always, any help appreciated!
I am trying to email a file from a B4A app.
I am getting the following permissions:
PERMISSION_READ_EXTERNAL_STORAGE,
PERMISSION_WRITE_EXTERNAL_STORAGE
This is the code I am using, along with the FileProvider class:
In Starter:
B4X:
Sub Process_Global
Public Provider As FileProvider
Public AppFolder as String
End Sub
B4X:
Sub Service_Create
Provider.Initialize
End Sub
In Main:
B4X:
Sub Activity_Create( FirstTime As Boolean )
' this activity's only purpose is to get permissions and start the next activity
Log( File.DirRootExternal ) ' to open external storage permission
Starter.AppFolder = rp.GetSafeDirDefaultExternal( "" )
End Sub ' Activity_Create()
In the activity:
B4X:
Sub Button_Click
Private ei As Email ' requires Phone library
Dim FileName as string
FileName = "My File"
File.Copy( Starter.AppFolder, FileName, Starter.Provider.SharedFolder, FileName )
Try
ei.To.Add( email )
ei.Body = FileName & " is attached."
ei.Subject = FileName
ei.Attachments.Add( Starter.Provider.GetFileUri( FileName ))
Dim in As Intent = ei.GetIntent
in.Flags = 1 ' FLAG_GRANT_READ_URI_PERMISSION
StartActivity( in )
Catch
Log( "Mail app failed" & CRLF & LastException )
ToastMessageShow( "Mail app failed", True )
End Try
The app crashes exactly on the ei.Attachments.Add statement with:
B4X:
Error occurred on line: 34 (FileProvider)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1704)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6142)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:804)
Caused by: java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority b4a.edsfl.fuzex.provider
at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:606)
at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:579)
at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:417)
... 19 more
Line 34 of the FileProvider class is:
B4X:
Return fp.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))
As always, any help appreciated!