Felipe Suman
Felipe Suman

Reputation: 421

Make your app a default app to open a certain file

How do I make my android app the default application to open a certain file type?

I tried to clear the defaults but the option is greyed out, does anyone know how to do this?

I want to make my app open with my something.whatever files in android.

Upvotes: 20

Views: 59256

Answers (6)

Ali Ahmed
Ali Ahmed

Reputation: 313

You can't force user to set you app as default but you can show user option to choose your app as default

Intent(Intent.ACTION_VIEW).apply {
    try {
        type = "application/pdf"
        addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
        startActivity(this)
    } catch (e: Exception) {
        toast("No app can handle this")
    }
}

Don't forget to add Intent-Filter in your activity tag in Manifest, so your app can be shown in a list for selectable as default app

Upvotes: 0

Boe-Dev
Boe-Dev

Reputation: 1595

Try this

Intent i = new Intent();        
   i.setAction(android.content.Intent.ACTION_VIEW);
   i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   i.setDataAndType(Uri.parse("file://"+path), 
       "application/vnd.android.package-archive");
   startActivity(i);

The path variable is your path.

Upvotes: 1

Eric Leschinski
Eric Leschinski

Reputation: 153872

In Android, how to associate file with a different program.

I'm using a "Droid Maxx" with Android Version 4.4.4

How to make a something.html file open with a file editor instead of firefox after you've associated firefox to always be associated with *.html files.

You have to clear out the default setting for the app that has associated with a filetype.

Do this

  1. Go to "Settings". It's in the app list.
  2. Under Device, click "Apps".
  3. Scroll down and click Firefox.
  4. Under the "Launch by default" entry, click "Clear defaults".
  5. Open your something.html file again.

Once again you are presented with a choice with what kind of program you want to open this file with.

If you want to associate and disassociate file types with apps indivdiaully:

There is a third party app called: Default App Manager Lite:

https://play.google.com/store/apps/details?id=com.appiator.defaultappmanager

Then you can run the program and manage your filetype -> default app associations individually.

Upvotes: 6

Yugandhar Babu
Yugandhar Babu

Reputation: 10349

I think in android every app/activity must have some intent actions and categories in its manifest file. In this intent settings only you have to make your app as default.

Even you write default in manifest, if any other apps found with same intent settings, android system will display all apps with same settings. user has to select one of them, there only it provide one check box to make one app as default for next time onwards. If user didn't check it the list will be displayed every time user opens the file.

I hope it may help you.

Upvotes: 1

Nanne
Nanne

Reputation: 64399

You cannot force this, and you shouldn't be able to. What you can do is make known your app can open the filetype. The user gets the standard "what program do you wish to use" dialog, and the user can select something as default. If the user has allready selected a default, he/she needs to undo that before the dialog appears (obviously, otherwise a 'default' wouldn't have a lot of effect, now would it?)

You can tell the world (aka: android) that you want to open a certain file type by adding an intent-filter. What you basically do is put in your manifest that an activity in your app knows how to handle the filetype (or website/protocol etc). That's quite easy to find, a random question here on SO about the same issue would be: Android intent filter for a particular file extension?

Upvotes: 17

Tchoupi
Tchoupi

Reputation: 14681

This subject has already been covered here: Register to be default app for custom file type

Add it to you intent-filter:

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

Upvotes: 11

Related Questions