0

I've been trying to add my PDF reader app as an implicit intent when a user clicks a pdf file from the file manager app, but my app doesn't show as an option to open that pdf file, instead only other apps like Adober Reader, and Google Reader show. How can I do that, I already tried adding the intent filter in the activity in the manifest.xml, but it doesn't work. I will show the the manifest.xml file as I have tried until this moment, but still don't getting the expected result.

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

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

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

    <activity android:name=".ActivityPdfView" >

    </activity>
    <activity android:name=".ActivityMain" >

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

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

            <category android:name="android.intent.category.LAUNCHER" />
            <data android:scheme="http" />
            <data android:host="*" />
            <data android:mimeType="application/pdf" />

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

            <category android:name="android.intent.category.LAUNCHER" />
            <data android:scheme="file" />
            <data android:host="*" />
            <data android:pathPattern=".*\\.pdf" />

        </intent-filter>
    </activity>

    <activity
        android:name=".ActivitySetting"
        android:label="@string/title_activity_setting" />

    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />

    <!-- This meta-data tag is required to use Google Play Services. -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <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>

</application>

</manifest>
cardaguh
  • 13
  • 4

1 Answers1

0

You have three <intent-filter> elements that are immediate children of <application>. Those will be ignored. If you want an <intent-filter> to trigger an <activity>, the <intent-filter> needs to be a child of that <activity>.

None of your ActivitySplash <intent-filter> elements are likely to be used. If you want to respond to ACTION_VIEW, you use <action android:name="android.intent.action.VIEW" /> and <category android:name="android.intent.category.DEFAULT" />, not <action android:name="android.intent.action.MAIN" /> and <category android:name="android.intent.category.LAUNCHER" />.

Since file Uri schemes have been largely banned since Android 7.0, any file <intent-filter> is unlikely to be used. Add an <intent-filter> for a content Uri and the application/pdf MIME type for greater compatibility.

Since http Uri schemes will be unusable by default on Android P, make sure that you support https in addition to http.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you, I am trying to do what you said, however in which Activity do I need to put the intent filters to make my app to appear as an implicit intent when a pdf file is selected in another app? – cardaguh May 04 '18 at 19:56
  • @cardaguh: It would be in whatever activity you wanted to have get control when the user selects the PDF. I can't tell you which of your activities should be offering to view the PDF. – CommonsWare May 04 '18 at 19:59
  • I already added the intent filters in every activity, however my app doesn't appear as an option in the file manager when I selected a pdf file. What I am doing wrong? – cardaguh May 04 '18 at 20:02
  • @cardaguh: Well, as I pointed out in my answer, your `` elements are mostly incorrect. – CommonsWare May 04 '18 at 20:33
  • Thank you for your help, I will try to solve the issue modifying the intent filters then. – cardaguh May 04 '18 at 21:00