Java Code Examples for android.content.pm.PackageManager#getPreferredActivities()

The following examples show how to use android.content.pm.PackageManager#getPreferredActivities() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: paper-launcher   File: CustomizationDialog.java    License: MIT License 6 votes vote down vote up
private boolean isPaperLauncherDefault() {
    final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);

    List<IntentFilter> filters = new ArrayList<>();
    filters.add(filter);

    String paperLauncherPackageName = mLauncherActivity.getPackageName();
    List<ComponentName> activities = new ArrayList<>();

    PackageManager packageManager = mLauncherActivity.getPackageManager();
    packageManager.getPreferredActivities(filters, activities, null);

    for (ComponentName activity : activities) {
        if (paperLauncherPackageName.equals(activity.getPackageName())) {
            return true;
        }
    }

    return false;
}
 
Example 2
private static boolean isLauncherInstalled(Context context, String packageName) {
    final IntentFilter filterCategory = new IntentFilter(Intent.ACTION_MAIN);
    filterCategory.addCategory(Intent.CATEGORY_HOME);

    List<IntentFilter> filters = new ArrayList<>();
    filters.add(filterCategory);

    List<ComponentName> activities = new ArrayList<>();
    final PackageManager packageManager = context.getPackageManager();

    packageManager.getPreferredActivities(filters, activities, null);

    for (ComponentName activity : activities) {
        if (packageName.equals(activity.getPackageName())) {
            return true;
        }
    }
    return false;
}
 
Example 3
private boolean isTrebuchetDefaultLauncher() {
    final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);

    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    filters.add(filter);

    final String myPackageName = getPackageName();
    List<ComponentName> activities = new ArrayList<ComponentName>();
    final PackageManager packageManager = getPackageManager();

    // You can use name of your package here as third argument
    packageManager.getPreferredActivities(filters, activities, null);

    for (ComponentName activity : activities) {
        if (myPackageName.equals(activity.getPackageName())) {
            Logger.logd(TAG, "Trebuchet IS default launcher!");
            return true;
        }
    }
    Logger.logd(TAG, "Trebuchet IS NOT default launcher!");
    return false;
}
 
Example 4
Source Project: BaldPhone   File: HomeScreenActivity.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isActivityDefault() {
    final List<IntentFilter> filters = new ArrayList<>();
    final ComponentName myComponentName = getComponentName();
    final String myPackageName = myComponentName.getPackageName();
    final List<ComponentName> activities = new ArrayList<>();
    final PackageManager packageManager = getPackageManager();
    packageManager.getPreferredActivities(filters, activities, myPackageName);
    return (activities.contains(myComponentName));
}