Android Question More file Provider issues... [solved]

Didier9

Well-Known Member
Licensed User
Longtime User
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:
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!
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I've got a feeling that this is nothing to do with your app but another app you have installed on the phone.

Couldn't find meta-data for provider with authority b4a.edsfl.fuzex.provider

Doing a google search for b4a.edsfl.fuzex.provider suggests this is a crypto wallet. It may have a malformed fileprovider.
If you uninstall this app or try on a different phone, what happens?
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
I've got a feeling that this is nothing to do with your app but another app you have installed on the phone.



Doing a google search for b4a.edsfl.fuzex.provider suggests this is a crypto wallet. It may have a malformed fileprovider.
If you uninstall this app or try on a different phone, what happens?
Edsfl is me (actually eds-fl.com), FuzeX is my app. Can't uninstall it and still debug it :)
 
Last edited:
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Sorry , didn't realise that. Did you take a look at the second post which seems to be the same problem as yours.
I looked at the post but not done anything else yet, I was on mobile but I will in a moment.
Thank you!
PS: no crypto wallet, it is a remote control app for some Bluetooth widgets I build :)
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Thank you Andrew, the post you linked to fixed it.
I was missing the additional declarations in the manifest...
B4X:
AddManifestText(
<uses-permission
  android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  android:maxSdkVersion="18" />
)
AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)
 
Upvote 0
Top