1

Android 操作系统在哪里存储有关哪个是默认浏览器的信息?例如,如果 Chrome 是我的默认浏览器,那么它应该将该信息存储在某个地方,对吗?

我拉了

数据/数据/com.android.browser/shared_prefs/com.android.browser_preferences.xml

另外,我想知道应用程序何时成为任何类型操作的默认应用程序,那么该信息存储在哪里?

但这似乎不包含该信息

是否有任何 adb 命令来获取此信息?

4

2 回答 2

3

爱德华的回答是完全正确的。不是默认浏览器在保存默认应用程序,系统会。

但是,您可以获得任何 Intent 的默认应用设置,如下所示:

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());
    }
}
于 2013-11-16T07:27:10.080 回答
2

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.

于 2013-11-15T23:20:10.690 回答