List of usage examples for android.content.pm PackageManager getPreferredActivities
public abstract int getPreferredActivities(@NonNull List<IntentFilter> outFilters, @NonNull List<ComponentName> outActivities, String packageName);
From source file:Main.java
public static boolean isMyLauncherDefault(Context context) { final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN); filter.addCategory(Intent.CATEGORY_HOME); List<IntentFilter> filters = new ArrayList<IntentFilter>(); filters.add(filter);/*from ww w. ja va2 s. c om*/ final String myPackageName = context.getPackageName(); List<ComponentName> activities = new ArrayList<>(); PackageManager packageManager = (PackageManager) context.getPackageManager(); // You can use name of your package here as third argument packageManager.getPreferredActivities(filters, activities, null); if (activities.size() == 0) //no default return true; for (ComponentName activity : activities) { if (myPackageName.equals(activity.getPackageName())) { return true; } } return false; }
From source file:com.nbplus.vbroadlauncher.HomeLauncherActivity.java
/** @Override/* w w w . j a v a2 s. com*/ protected void onNewIntent(Intent intent) { //super.onNewIntent(intent); if (intent == null) { return; } String action = intent.getAction(); Log.d(TAG, "onNewIntent.. action = " + action); // if (PushConstants.ACTION_PUSH_STATUS_CHANGED.equals(action) || PushConstants.ACTION_PUSH_MESSAGE_RECEIVED.equals(action)) { // setPushServiceStatus(intent.getIntExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, PushConstants.PUSH_STATUS_VALUE_DISCONNECTED)); // // if (mActivityInteractionListener != null) { // for (OnActivityInteractionListener listener : mActivityInteractionListener) { // listener.onPushReceived(intent); // } // } // } } */ protected boolean isMyLauncherDefault() { 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 = (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())) { return true; } } return false; }