androidadbandroid-browser

Where is information about default browser stored in Android?


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?


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());
        }
    }