Search code examples
androidandroid-studiopdfandroid-10.0file-manager

Android Q PDF type file extension open through file manager


I'm trying to let user have the option to open pdf files through my app. So, when a user clicks on a pdf file from the file manager they should have the option to open it with my app along with other pdf reader apps if available in their device. I've added the following intent filters in the manifest by scouring through various answer here. They seem to work below Api 29 (my app shows in the list upon clicking a pdf file). But for API Q the app isn't showing on the list.

Intents filters:

           <!--For pdf-->
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="content"
                    android:host="*"
                    android:pathPattern=".*\\.pdf"
                    android:mimeType="*/*"  />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="http" />
                <data android:host="*" />
                <data android:pathPattern=".*\\.pdf" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="http" />
                <data android:host="*" />
                <data android:mimeType="application/pdf" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="file" />
                <data android:host="*" />
                <data android:pathPattern=".*\\.pdf" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.EDIT" />
                <category android:name="android.intent.category.DEFAULT" />
                <data
                    android:host="*"
                    android:mimeType="*/*"
                    android:pathPattern=".*\\.pdf"
                    android:scheme="file" />
            </intent-filter>

            <intent-filter android:priority="999">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.OPENABLE" />

                <data android:host="*" />
                <data android:mimeType="application/octet-stream" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.pdf" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\.pdf" />
                <data android:pathPattern=".*\\..*\\..*\\.pdf" />
                <data android:pathPattern=".*\\..*\\.pdf" />
                <data android:pathPattern=".*\\.pdf" />
                <data android:scheme="content" />
            </intent-filter>
            <!--end pdf-->

How can I allow pdf files to be opened with my app in Android Q and above too? PS: All necessary permissions are taken


Solution

  • I'm using this code for this

    <activity
            android:name=".OpenPdfActivity"
            android:theme="@style/OpenPdfActTheme">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
    
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
    
                <data
                    android:mimeType="application/pdf"
                    android:scheme="file" />
                <data
                    android:mimeType="application/pdf"
                    android:scheme="content" />
            </intent-filter>
        </activity>