Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register to be default app for custom file type

Tags:

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?

like image 554
Aymon Fournier Avatar asked Aug 12 '10 07:08

Aymon Fournier


People also ask

How do I change the default app for file types in Android?

To set a default appFind and tap Settings > Apps & notifications > Default apps. Tap the type of app you want to set, and then tap the app you want to use as default.

How do I associate a file type with a program?

Open the Control Panel. In the Control Panel, click the Default Programs option. Click the Associate a file type or protocol with a program option. In the Default apps window, scroll to the bottom and select Choose defaults by file type.


2 Answers

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.

like image 156
Dan Borza Avatar answered Oct 03 '22 07:10

Dan Borza


I think that you don't choose that. This is handle by the system. Same thing when you send an intent to be handled by a map, If you have skyfire for instance, the system pops up a window an you can choose the application and choose if you want it to always open this kind of file.
Unless of course if your application is the only one to open this kind of file.

Edit
I think if you want your app to say "hey I'm able to open these .cool files", you need to set up <intent-filters> with a tag <data> and specificy the mimeType or Uri. Check here for more details.

like image 43
Sephy Avatar answered Oct 03 '22 06:10

Sephy