How do I find the packages that have Launch by Default set?

Kenneth Evans

I would like to find the packages that have "Launch by Default" set in the Android application manager. The application manager typically says something like "This app is set to open by default for some actions" and has a "Clear defaults" button for these packages.

As an example this image shows the application manager page for Adobe Reader, which I have set as the default for opening PDF files. I would like to be able to determine programmatically that this package (com.adobe.reader) has a "Launch by Default" set and, more generally, all the packages that have such a "Launch by Default" set. (Clearly the Application Manager can do this.)

Adobe Reader Application Manager Page

I can get all the installed packages via:

  List<PackageInfo> packages = getPackageManager()
          .getInstalledPackages(0);

How do I tell which ones have "Launch by Default" set? Is there a way to also find the actions?

Thanks.

Kenneth Evans

This seems to work for me:

/**
 * Get info on the preferred (launch by default) applications.
 * @return
 */
public String getPreferredAppInfo() {
    List<PackageInfo> packages = getPackageManager()
            .getInstalledPackages(0);
    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    List<ComponentName> activities = new ArrayList<ComponentName>();
    String info = "";
    int nPref = 0, nFilters = 0, nActivities = 0;
    PackageInfo pkg = null;
    for (int i = 0; i < packages.size(); i++) {
        pkg = packages.get(i);
        nPref = getPackageManager().getPreferredActivities(filters,
                activities, pkg.packageName);
        nFilters = filters.size();
        nActivities = activities.size();
        if (nPref > 0 || nFilters > 0 || nActivities > 0) {
            // This is a launch by default package
            info += "\n" + pkg.packageName + "\n";
            for (IntentFilter filter : filters) {
                info += "IntentFilter:\n";
                for (int j = 0; j < filter.countActions(); j++) {
                    info += "    action: " + filter.getAction(j) + "\n";
                }
                for (int j = 0; j < filter.countCategories(); j++) {
                    info += "    category: " + filter.getCategory(j) + "\n";
                }
                for (int j = 0; j < filter.countDataTypes(); j++) {
                    info += "    type: " + filter.getDataType(j) + "\n";
                }
                for (int j = 0; j < filter.countDataAuthorities(); j++) {
                    info += "    data authority: "
                            + filter.getDataAuthority(j) + "\n";
                }
                for (int j = 0; j < filter.countDataPaths(); j++) {
                    info += "    data path: " + filter.getDataPath(j)
                            + "\n";
                }
                for (int j = 0; j < filter.countDataSchemes(); j++) {
                    info += "    data path: " + filter.getDataScheme(j)
                            + "\n";
                }
                // for (ComponentName activity : activities) {
                // info += "activity="
                // + activity.flattenToString() + "\n";
                // }
            }
        }
    }
    return info;
}

I was thrown by the fact that the return value for PackageManager.getPreferredActivities() seems to be zero instead of the total number of registered preferred activities. If it weren't always zero, checking for non-zero would be sufficient to see if a package has "launch by default" set. I also found PackageManager.getPreferredPackages() always returned zero for me. I also found passing null for PackageManager.getPreferredActivities() for the filters and activities (as mentioned in the Javadoc) gave a NullPointerException.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

flag package in Go - do I have to always set default value?

From Dev

How do I find the packages that have Launch by Default set?

From Dev

How do I set default timezone in cakephp?

From Dev

how to have go find packages online?

From Dev

How do I resolve `The following packages have unmet dependencies`

From Dev

How do I change the default library path for R packages

From Dev

How do I set default values in a record

From Dev

Anaconda - I have set up an environment, how do I use it?

From Dev

How do I set the default theme in phpMyAdmin?

From Dev

How do I find out which boot loader I have?

From Dev

How do I set the default terminal profile?

From Dev

How do I set fish as the default shell?

From Dev

How do I find out which boot loader I have?

From Dev

How do I find all files that do NOT have SYSTEM permission?

From Dev

How do I set the default terminal profile?

From Dev

How to find where I have set "umask 077"?

From Dev

How do I set Nautilus to Default view?

From Dev

How do I list the default installed packages?

From Dev

How do I view packages that I have installed

From Dev

How do I set default Action for Controller?

From Dev

How do I launch JemmyFXBrowser?

From Dev

How do I launch Bash for windows when I have cygwin installed?

From Dev

How do I set fish as the default shell?

From Dev

How do I set the default icon set and wallpaper for new users?

From Dev

how do I set the default timezone in a script?

From Dev

How do I find out if I have a separate boot partition?

From Dev

How do I find installed packages that have no install candidate?

From Dev

how to find packages that have a couple of the same dependencies?

From Dev

How to change default Midnight Commander appearance, so I don't have to change it every time I launch a terminal?

Related Related

  1. 1

    flag package in Go - do I have to always set default value?

  2. 2

    How do I find the packages that have Launch by Default set?

  3. 3

    How do I set default timezone in cakephp?

  4. 4

    how to have go find packages online?

  5. 5

    How do I resolve `The following packages have unmet dependencies`

  6. 6

    How do I change the default library path for R packages

  7. 7

    How do I set default values in a record

  8. 8

    Anaconda - I have set up an environment, how do I use it?

  9. 9

    How do I set the default theme in phpMyAdmin?

  10. 10

    How do I find out which boot loader I have?

  11. 11

    How do I set the default terminal profile?

  12. 12

    How do I set fish as the default shell?

  13. 13

    How do I find out which boot loader I have?

  14. 14

    How do I find all files that do NOT have SYSTEM permission?

  15. 15

    How do I set the default terminal profile?

  16. 16

    How to find where I have set "umask 077"?

  17. 17

    How do I set Nautilus to Default view?

  18. 18

    How do I list the default installed packages?

  19. 19

    How do I view packages that I have installed

  20. 20

    How do I set default Action for Controller?

  21. 21

    How do I launch JemmyFXBrowser?

  22. 22

    How do I launch Bash for windows when I have cygwin installed?

  23. 23

    How do I set fish as the default shell?

  24. 24

    How do I set the default icon set and wallpaper for new users?

  25. 25

    how do I set the default timezone in a script?

  26. 26

    How do I find out if I have a separate boot partition?

  27. 27

    How do I find installed packages that have no install candidate?

  28. 28

    how to find packages that have a couple of the same dependencies?

  29. 29

    How to change default Midnight Commander appearance, so I don't have to change it every time I launch a terminal?

HotTag

Archive