Register to be default app for custom file type

Aymon Fournier picture Aymon Fournier · Aug 12, 2010 · Viewed 21.2k times · Source

Register to be able to open files of custom type. Say i have .cool files, and if the user tries to open it, Android asks if they would like to open it with my application. How?

Answer

Dan Borza picture Dan Borza · Feb 16, 2012

You can add the following to the AndroidManifest.xml file inside the activity that has to open the file (pdf in our case)

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

Make sure you specify the proper mime format. The user will be prompted to choose your app if she wants to open the "pdf" file.

Check also Android intent filter: associate app with file extension for more details.