8

I want to check if my application is set as the default application for the Intents I'm handling inside my App.

As an example ff more than one application supports to open a specified file format. I need to make my application as a default application from my code. How it possible to make my application a default (from the code)? Can anyone help me?

At least I would like to check this on startup of my app and redirect the user to fill in some information if my App is not set as the default on the device.

Janusz
  • 187,060
  • 113
  • 301
  • 369
SRS
  • 103
  • 2
  • 7
  • Please define what you mean by "is a default". – CommonsWare Jul 27 '10 at 05:44
  • 1
    Do you mean like having two different apps installed handling the same activity? The built in "messaging" and "Handcent SMS" for handling Short messaging services? If the user have set a default app - you want to know if its yours or not? Have I understood your question correct? – Benny Skogberg Jul 27 '10 at 07:46
  • I download ics file from my application.Another one application also able to download the ics file.When the user try to open the file the Android device will list the possible application to perform. When the user select my application to open the ics file at that time i will get some details from the user(about the user). If they select my application as a default i won't ask the detail about the user.For that i need to check my application is a default application or not.If it default i will directly open the file otherwise i wish to get the details about user. – SRS Jul 27 '10 at 08:42

2 Answers2

4

As far as I know this is not possible. That dialogue is handled by the system - your app will only be launched if the user picks your app from the list.

Allowing such a behaviour would impact the user's ability to control their default applications, and from a technical point of view would mean a process and its memory would have to be allocated to every app in the list every time such a list appeared.

adamnfish
  • 10,935
  • 4
  • 31
  • 40
3

You could use this method:

public static boolean isOurAppDefault(Context context) {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com"));
    ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(browserIntent,PackageManager.MATCH_DEFAULT_ONLY);
    String defaultBrowserPkg = null;
    if (resolveInfo != null) {
        if (resolveInfo.activityInfo != null) {
            defaultBrowserPkg = resolveInfo.activityInfo.packageName;
        }
    }
    return TextUtils.equals(context.getPackageName(), defaultBrowserPkg);
}

It's actual for some editor or browser. In other case use different Uri data for intent.

Djek-Grif
  • 1,391
  • 18
  • 18