Search code examples
androidandroid-intentandroid-contentprovider

Why doesn't my filemanager respond to ACTION_GET_CONTENT intent?


I made a filemanager and I want it to respond to ACTION_GET_CONTENT intents. So I have this in my FileChooser activity in the AndroidManifest.xml:

        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.OPENABLE" />
        </intent-filter>

(In fact, in the docs it says that adding

            <data android:type="image/*" />

serves to choose a photo, but Android Studio is telling me that Cannot resolve symbol 'image/*'.)

Yet, my app did not answer to this request. Why?? For example, it does not respond when I try to attach a file with K9.

My full AndroidManifest.xml, where you can see my tries:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.floritfoto.apps.xvf"
    android:versionCode="108"
    android:versionName="3.9">

    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
        tools:ignore="ScopedStorage" />

    <application
        tools:ignore="AllowBackup"
        android:supportsRtl="false"
        android:allowBackup="true"
        android:requestLegacyExternalStorage="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:name="com.floritfoto.apps.xvf.ZForDebug"
        android:theme="@style/MyThemeNonFS" >
        <activity
            android:name=".XvfActivity"
            android:label="@string/app_name"
            android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <!--
                -->
            </intent-filter>
        </activity>

        <activity
            android:exported="true"
            android:name=".Thumbs" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.LAUNCHER" />
                <!--
                -->
            </intent-filter>
        </activity>
        <activity
            android:name=".Foto"
            android:exported="true"
            tools:ignore="ExportedActivity">
            <intent-filter tools:ignore="AppLinkUrlError">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity>
        <activity
            android:name="XvfPreferences"
            android:label="Settings">
        </activity>
        <activity
            android:name="FolderList"
            android:label="Fima"
            android:exported="true"
            android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
            android:icon="@drawable/fima_launcher_128" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <!--
                -->
            </intent-filter>
        </activity>
        <activity
            android:name="FileChooser"
            android:label="File Chooser"
            android:exported="true">
            <intent-filter>
                <action android:name="org.openintents.action.PICK_FILE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="file" />
                <data android:mimeType="*/*" />
            </intent-filter>
            <intent-filter>
                <action android:name="org.openintents.action.PICK_FILE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="file" />
            </intent-filter>
            <intent-filter>
                <action android:name="org.openintents.action.PICK_FILE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="org.openintents.action.PICK_DIRECTORY" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="file" />
            </intent-filter>
            <intent-filter>
                <action android:name="org.openintents.action.PICK_DIRECTORY" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.GET_CONTENT" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.OPENABLE" />
                <data android:mimeType="*/*" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.GET_CONTENT" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.OPENABLE" />
                <data android:scheme="file" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.GET_CONTENT" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.OPENABLE" />
            </intent-filter>
        </activity>
        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>

    </application>

</manifest>

EDIT: If I don´t set fc.setType("...") my app is called...


Solution

  • According to this answer by @CommonsWare , ACTION_GET_CONTENT is managed by the OS itself in modern versions of Android. So it seems that we are forced to use what the OS wants.