Alex Curran
Alex Curran

Reputation: 8828

Launching default apps with intents

How, in android, do I start an app set as the default (i.e. Handcent for Messaging, Dolphin for browsing)?

I can only find how to use definite package names for intents:

Intent i = new Intent(Intent.ACTION_MAIN);
        i.addCategory(Intent.CATEGORY_LAUNCHER);

        switch (position) {
        case 0: //messages
            i.setPackage("com.android.mms");
            break;
        case 1: //inbox
            i.setPackage("com.android.email");
            break;
        case 2: //browser
            i.setPackage("com.android.browser");
        default:
            i = null;
        }

Upvotes: 0

Views: 1870

Answers (2)

cdhabecker
cdhabecker

Reputation: 1703

You can search for apps that satisfy a given Intent (e.g., ACTION_SEND), decide which one you want, retrieve its component name, and then launch it with a different Intent that specifies the component name.

Start with:

Intent intent = new Intent(...);
List<ResolveInfo> list = getPackageManager().queryIntentActivities(
    intent, PackageManager.MATCH_DEFAULT_ONLY);

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006674

How, in android, do I start an app set as the default (i.e. Handcent for Messaging, Dolphin for browsing)?

"Default" is for a specific operation (e.g., sending a message), not for some abstract notion of "Messaging" in general.

Also, the code you are showing above uses things that are not in the SDK (namely, specific packages). Your code will break on some devices, where the device manufacturer has replaced the app. Your code may break in future versions of Android, when the stock apps are refactored or otherwise renamed.

I think you need to reconsider what it is you are trying to accomplish.

Upvotes: 2

Related Questions