Intent. Filter program that appears in the "open with" option

Asked

Viewed 446 times

0

Today the option to "open with" lists several programs that are installed on mobile and including my app. I would like my app to be an option only for the files of the extension it works, in this case "*. rlc".

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

        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="*/*"/>
            <data android:pathPattern=".*\\.rlc" />
        </intent-filter>
    </activity
  • My app opens normally. The problem is that my app is listed for any file. Image for example. I don’t want to open image with my app understands?

  • So you want to filter it to only open rlc, right?!

  • Yes, let my app be listed only in rlc files. Today it is listed for any type of file. It’s not a real problem, but I think it gets a little boring for the person to appear a program that can’t perform the function he wants to understand? For example Android offer my app to a jpg.

  • The way you did is right. But try to add this: <category android:name="android.intent.category.BROWSABLE" />&#xA; <data android:scheme="file" /> <data android:host="*"

  • It worked! Now if I try to open a cbr, for example, my app is not listed. If I try to open a rlc it appears and I have to leave as default application. PERFECT! thank you very much!

2 answers

1

See how the syntax of <data>:

<data android:scheme="string"
      android:host="string"
      android:port="string"
      android:path="string"
      android:pathPattern="string"
      android:pathPrefix="string"
      android:mimeType="string" />

Now see below how I can be set in your activity in the AndroidManifest.xml to work properly open in only one specific extension. For example .rlc:

<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="file" />
    <data android:mimeType="*/*" />
    <data android:pathPattern=".*\\.rlc" />
    <data android:host="*" />
</intent-filter>

0

Add "mimetype" to Androidmanufest.xml in your Intent with the extension that will be supported.

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

More information can search the Documentación Oficial

  • In this case it would only replace "application/pdf" with "application/rlc"?

  • I switched from "application/pdf" to "application/rlc" and removed pathPattern. Now it does not appear to open any file type.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.