Skip to content

android provider path need be written as "${applicationId}.fileProvider.com.crazecoder.openfile" #354

@hejuekun

Description

@hejuekun

i found that my provider do not work. and always get error like Failed to find configured root that contains /data/data/xxxx/files/testt.txt
and here is my config. like

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileProvider"
            android:exported="false"
            android:grantUriPermissions="true"
            android:requestLegacyExternalStorage="true"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/my_paths"
                tools:replace="android:resource" />
        </provider>

with th my_paths is

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="externalPath" path="."/>
    <files-path name="filePath" path="."/>
    <cache-path name="cachePath" path="."/>
</paths>

after long times debug. i found some clues

[        ] E/flutter ( 3660): 	at com.crazecoder.openfile.utils.FileUtil.getFileUri(FileUtil.java:230)
[        ] E/flutter ( 3660): 	at com.crazecoder.openfile.OpenFilePlugin.startActivity(OpenFilePlugin.java:140)
[        ] E/flutter ( 3660): 	at com.crazecoder.openfile.OpenFilePlugin.doOpen(OpenFilePlugin.java:119)
[        ] E/flutter ( 3660): 	at com.crazecoder.openfile.OpenFilePlugin.onMethodCall(OpenFilePlugin.java:75)

It is written like this
uri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileProvider.com.crazecoder.openfile", new File(filePath));

But the readme.md clearly shows

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="xxx.xxx.xxxxx">
    <application>
        ...
        <provider
                android:name="androidx.core.content.FileProvider"
                android:authorities="${applicationId}.fileProvider"
                android:exported="false"
                android:grantUriPermissions="true"
                tools:replace="android:authorities">
            <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/filepaths"
                    tools:replace="android:resource" />
        </provider>
    </application>
</manifest>

in homepage

I'm a little confused

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions