Android Question FileProvider to read from another app directory

GaNdAlF89

Active Member
Licensed User
Hi, I have two applications installed and I want to read a file from 1st app that is stored in the directory of the 2nd app.
How can I set the xml related to FileProvider of 1st app? Thanks

The file is stored in this path of 1st app:
B4X:
RuntimePermissions.GetSafeDirDefaultExternal("") + "/dwl/files"

AndroidManifest of 1st app
B4X:
AddApplicationText(<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="$PACKAGE$.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/fileprovider_paths"/>
</provider>)

CreateResource(xml,fileprovider_paths,
<paths>
    <external-files-path
        name="apk_update"
        path="/dwl/files/"/> '2nd app
</paths>)
 
Last edited:

GaNdAlF89

Active Member
Licensed User
You should send an intent to the second app and the second app should return the file.
Thanks for your reply. However, I wanted to try this:
in both of my apps I use the FileProvider class, so the
B4X:
RuntimePermissions.GetSafeDirDefaultExternal("")
returns a path to storage that, among the two apps, differs only for the package name of each app. Finally, I replaced the package name retrieved from 1st app with the package name of the 2nd app, and now from 1st app I am able to get the file stored in the 2nd app path.

Relative Manifest.xml:
B4X:
CreateResource(xml,fileprovider_paths,
<paths>
    <external-path name="name" path=""/>
</paths>)


It works! But, why? Considering that
You cannot directly read files of other apps.
 
Last edited:
Upvote 0

GaNdAlF89

Active Member
Licensed User
You cannot directly read files of other apps.

The relevant example is this one: https://www.b4x.com/android/forum/t...om-your-app-with-file-provider.70458/#content
You should send an intent to the second app and the second app should return the file.
Sorry but I have some difficulties to proceed.
My 1st app is a launcher for the 2nd app. 2nd app downloads new update apk (of itself, and save it into its folder) and then invoke the 1st app to install it.

How can I proceed in my case, to let the 1st app get the apk update from 2nd app? Can you help me, please?
 
Last edited:
Upvote 0
Top