Android Question Question how to use the FilProvider for two separate functions?

WebQuest

Active Member
Licensed User
Hello community,
I'm having trouble using the fileprovider.
I have two functions that use the same FileProvider.
a function launches an intent to display pdf so I declared the path in the editormanifest:
Editormanifest:
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,
   <external-files-path name="name" path="List/Archivio/" /> 'file path to launch the intent
)

The other function uses the fileprovider to launch the camera of the device with an intent:
Editormanifest:
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,
   <external-files-path name="name" path="shared" />'Path
)

The problem is that by declaring both paths in the editormanifest at runtime the system always executes the last declaration, so I get a java.lang.reflect.invocationTargetException error for one of the two functions.

Does anyone know how to index the two functions with different paths?
 

WebQuest

Active Member
Licensed User
Thanks guys I found the solution ?.
I share the solution in case it may be useful to others.
EditorManifest:
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,
   <external-files-path name="name" path="List/Archivio/" />
)

Just edit FIleProvider module:
Basically the Fileprovider module uses a SharedFolder variable which is initialized with the term 'shared'
Basically the Fileprovider module uses a SharedFolder variable which is initialized with the term shared in File.Internal. In my case the first intent points to File.DriDefultExternal. By replacing the internal direction and aligning the path of the directions of the two functions I got what I needed.

FileProvider Module:
Sub Class_Globals
    Public SharedFolder As String
    Public UseFileProvider As Boolean
    Private rp As RuntimePermissions
End Sub

Public Sub Initialize
    Dim p As Phone
    If p.SdkVersion >= 24 Or File.ExternalWritable = False Then
        UseFileProvider = True
        SharedFolder = File.Combine(File.DirDefultExternal, "List/Archivio") 'X'
        File.MakeDir("", SharedFolder)
    Else
        UseFileProvider = False
        SharedFolder = rp.GetSafeDirDefaultExternal("List/Archivio")'X'
    End If
    Log($"Using FileProvider? ${UseFileProvider}"$)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…