0

I am new to this site so sorry if I posted in the wrong place. My question is simple, How can I set my app to open specific file types. For example, When someone clicks on a zip file in any other app I want my app to be in the list of apps that are able to open this type.

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30

2 Answers2

0

You could easily do this by adding a <intent-filter> to your application in your manifest file.

<activity android:name=".ActivityName">
    <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=".*\\.zip" />
        <data android:host="*" />
    </intent-filter>
</activity>

pathPattern is where you specify what extension you want to match.

Reference & thanks to Brian Pellin's answer here.

sanjeev
  • 1,664
  • 19
  • 35
0

You should add an IntentFilter like this one in your Manifest to your desired Activity:

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

Read more about Intent and IntentFilter.

You can customize some values, such as host and pathPattern as desired.

You can get information about the file provided by another Application through in your Activity, via getIntent(). Read the content of the Intent to get more info about the file.

Vitor Hugo Schwaab
  • 1,545
  • 20
  • 31