Question

Where does Android OS store information about which is the default browser? For example, if Chrome is my default browser then it should store that information somewhere, right?

I pulled

data/data/com.android.browser/shared_prefs/com.android.browser_preferences.xml

Also, I want to know whenever an app becomes a default app for any kind of action then where is that information stored?

But that does not seem to contain that information

is there any adb command to fetch this informaiton?

Was it helpful?

Solution

Eduard's answer is fully correct. Not the default browser is saving default apps, the system does.

However, you can get default app settings for any Intent like this:

public static void getDefaultApp(final Context context, final String url) {
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    ComponentName component = i.resolveActivity(context.getPackageManager());
    if (component == null) {
        // no app at all can handle this intent
        // there might be profile restrictions applied since android 4.3
    } else if (component.getPackageName().equals("android")) {
        // there are multiple apps available handling your intent
        // no default app is set, the Chooser will be shown
    } else if (component.getPackageName().equals("com.android.browser")) {
        // the default browser will be shown
        // there might be multiple apps installed handling your intent
        // however the user picked the default browser
    } else if (component.getPackageName().equals("com.android.chrome")) {
        // chrome will handle your intent
        // there are multiple apps installed handling your intent most likely
        // however the user picked this app
    } else {
        // some other app will handle your intent
        // there are multiple apps installed handling your intent most likely
        // however the user picked this app
        Log.d(TAG, "user choice package: " + component.getPackageName());
        Log.d(TAG, "user choice class:   " + component.getClassName());
    }
}

OTHER TIPS

Android uses Intent objects to communicate between activites. One activity creates an intent specifying the action and data, and sends it to the system. The system then determines which application is best suited to respond to that intent and forwards that intent to the chosen application.

For example, examining the AndroidManifest.xml file for the browser, I see that it contains an <intent-filter> entry that specifies this activity should be launched for intents with schemes "http", "https", "inline", "text/html", "text/plain", and so forth.

Some applications may specify the same intent filters, in which case there will be a conflict. For example, there are a number of Wikipedia applications which register intent filters for "http://wikipedia.org/" or something along those lines.

When the system encounters a conflict, it pops up a dialog that says "Complete action using" and contains a list of the applications that matched the intent filter. At this time, the user selects which activity should be used, and optionally instructions the system to remember their choice.

In the Wikipedia example, suppose the user selected the Wikipedia app and chose to have the system remember their choice. From that point forward, the system would always launch the Wikipedia app for intents that started "http://wikipedia.org/". It would still launch the browser for intents that start with "http:" because those won't match the Wikipedia app's intent filter.

As for where the system actually keeps its list of intents, applications, and user preferences, I can't answer that part. It's probably part of Android's internal data and its exact location is not part of the published API and possibly subject to change without notice. There's probably a way to tell the system to reset user preferences, but I don't know how, offhand.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top