1

I am working to create a basic file explorer app in Android, and I'm stuck on how to get FileProvider working so I can allow my app access to other file areas than just the basic allotment Android grants you by default.

I have tried to follow the guides I have been reading (https://developer.android.com/training/secure-file-sharing/setup-sharing.html and a few others), but I am at a loss, specifically the problem seems to lie in the fact that my @xml/filepaths is not registering within my manifest, I get the error: "Top level element is not completed."

Here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.hacktivity.datatemple">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="org.hacktivity.datatemple.fileprovider"
        android:grantUriPermissions="true"
        android:exported="false">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filepaths" />
    </provider>


    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

And in my file res/xml/filepaths.xml, I have the following:

<paths>
  <external-path path="/" name="root" />
</paths>
Graffiti Plum
  • 95
  • 1
  • 8
  • Did you try path="" . Path is relative the app's data files/ directory. A path of "/" I would think would be the directory files//, which looks to me like to me would give you the error top level element is not completed! – Tom Rutchik Jun 23 '23 at 22:20

1 Answers1

1

I get the error: "Top level element is not completed."

Tactically, the problem is that you are missing the opening <:

paths>
  <external-path path="/" name="root" />
</paths>

Strategically, FileProvider is not related to "allow my app access to other file areas than just the basic allotment Android grants you by default". FileProvider allows you to grant third-party apps access to content, stored as files, from a handful of standard locations.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • The mistake with the "<" was just here and not in the code of my project. – Graffiti Plum Oct 11 '16 at 18:47
  • If not FileProvider, then what allows me to access the rest of the file system in Android like various other apps I have used do? – Graffiti Plum Oct 11 '16 at 18:47
  • 1
    @GraffitiPlum: I do not know what you consider "the rest of the file system in Android" to mean. You cannot access arbitrary filesystem locations, except if you are running on a rooted device. You are welcome to explore [external storage](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html) by holding `READ_EXTERNAL_STORAGE` or `WRITE_EXTERNAL_STORAGE` permissions (including requesting them at runtime). – CommonsWare Oct 11 '16 at 19:11
  • I am still at a loss in understanding this; okay, for example I have an app (3rd party) which has access to list the directory of the root "/" of the file system. My app can't access what is listed in the root directory. What do I need to do to get this to happen? – Graffiti Plum Oct 12 '16 at 09:24
  • 1
    @GraffitiPlum: "What do I need to do to get this to happen?" -- presumably, your device is rooted and that third-party app is using superuser privileges. Or, possibly, the third-party app was pre-installed by the device manufacturer, and the manufacturer gave a dubious amount of privileges to the app. Or, possibly, your device has known security flaws, and your third-party app knows about those flaws and is exploiting them. However, more to the point of your question, **none of this has anything to do with `FileProvider`**. – CommonsWare Oct 12 '16 at 11:20