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

The following examples show how to use android.content.pm.PackageManager#getPreferredActivities() . 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 check out the related API usage on the sidebar.
Example 1
Source File: CustomizationDialog.java    From paper-launcher with 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
Source File: Utils.java    From always-on-amoled with GNU General Public License v3.0 6 votes vote down vote up
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
Source File: AggregationIntentService.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
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 File: HomeScreenActivity.java    From BaldPhone with 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));
}