Example usage for android.content.pm PackageManager GET_ACTIVITIES

List of usage examples for android.content.pm PackageManager GET_ACTIVITIES

Introduction

In this page you can find the example usage for android.content.pm PackageManager GET_ACTIVITIES.

Prototype

int GET_ACTIVITIES

To view the source code for android.content.pm PackageManager GET_ACTIVITIES.

Click Source Link

Document

PackageInfo flag: return information about activities in the package in PackageInfo#activities .

Usage

From source file:de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.java

private boolean _appIsInstalled(String packageId) {
    PackageManager pm = cordova.getActivity().getPackageManager();
    try {/*from ww  w. j ava  2 s  .  co  m*/
        pm.getPackageInfo(packageId, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:io.flutter.embedding.android.FlutterActivity.java

/**
 * The initial route that a Flutter app will render upon loading and executing its Dart code.
 * <p>//from w  w w  .j  a  v  a2 s.c  o m
 * This preference can be controlled with 2 methods:
 * <ol>
 *   <li>Pass a boolean as {@link #EXTRA_INITIAL_ROUTE} with the launching {@code Intent}, or</li>
 *   <li>Set a {@code <meta-data>} called {@link #INITIAL_ROUTE_META_DATA_KEY} for this
 *    {@code Activity} in the Android manifest.</li>
 * </ol>
 * If both preferences are set, the {@code Intent} preference takes priority.
 * <p>
 * The reason that a {@code <meta-data>} preference is supported is because this {@code Activity}
 * might be the very first {@code Activity} launched, which means the developer won't have
 * control over the incoming {@code Intent}.
 * <p>
 * Subclasses may override this method to directly control the initial route.
 */
@NonNull
protected String getInitialRoute() {
    if (getIntent().hasExtra(EXTRA_INITIAL_ROUTE)) {
        return getIntent().getStringExtra(EXTRA_INITIAL_ROUTE);
    }

    try {
        ActivityInfo activityInfo = getPackageManager().getActivityInfo(getComponentName(),
                PackageManager.GET_META_DATA | PackageManager.GET_ACTIVITIES);
        Bundle metadata = activityInfo.metaData;
        String desiredInitialRoute = metadata != null ? metadata.getString(INITIAL_ROUTE_META_DATA_KEY) : null;
        return desiredInitialRoute != null ? desiredInitialRoute : DEFAULT_INITIAL_ROUTE;
    } catch (PackageManager.NameNotFoundException e) {
        return DEFAULT_INITIAL_ROUTE;
    }
}

From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java

@Override
void updateFromConfigurationForm(FetcherOptionsDialog dialog) {
    appType = (dialog.isBoxChecked(R.id.system_apps) ? APP_TYPE_SYSTEM : 0)
            | (dialog.isBoxChecked(R.id.user_apps) ? APP_TYPE_USER : 0);

    type = (dialog.isBoxChecked(R.id.activities) ? PackageManager.GET_ACTIVITIES : 0)
            | (dialog.isBoxChecked(R.id.receivers) ? PackageManager.GET_RECEIVERS : 0)
            | (dialog.isBoxChecked(R.id.services) ? PackageManager.GET_SERVICES : 0)
            | (dialog.isBoxChecked(R.id.content_providers) ? PackageManager.GET_PROVIDERS : 0);

    protection = (dialog.isBoxChecked(R.id.permission_filter_world_accessible) ? PROTECTION_WORLD_ACCESSIBLE
            : 0) | (dialog.isBoxChecked(R.id.permission_filter_normal) ? PROTECTION_NORMAL : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_dangerous) ? PROTECTION_DANGEROUS : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_signature) ? PROTECTION_SIGNATURE : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_system) ? PROTECTION_SYSTEM : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_development) ? PROTECTION_DEVELOPMENT : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_unexported) ? PROTECTION_UNEXPORTED : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_unknown) ? PROTECTION_UNKNOWN : 0);

    includeOnlyProvidersAllowingPermissionGranting = dialog
            .isBoxChecked(R.id.only_providers_with_grant_uri_permission);

    boolean requireMetaData = dialog.isBoxChecked(R.id.metadata);
    requireMetaDataSubstring = requireMetaData ? dialog.getTextFromField(R.id.metadata_substring) : null;

    testWritePermissionForProviders = dialog.isBoxChecked(R.id.write_permission);
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static PackageInfo getPackageInfo(Context context, String packageName) {
    PackageInfo packageInfo = null;/*from w  w w . java2  s .  c o m*/
    PackageManager pm = context.getPackageManager();
    try {
        packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
    } catch (NameNotFoundException e) {
    }
    return packageInfo;
}

From source file:study.tdcc.act.MainCalendar.java

/**
 * ?//from  w w  w  .  j av a  2s  .  c  om
 *
 */
private void setCustomTitle() {
    Log.d("DEBUG", "MainCalendar setCustomTitle Start");
    tvCustomTitle.setText(getString(R.string.act_name1));
    StringBuilder sbObj = new StringBuilder();
    sbObj.append(getString(R.string.title_version));
    PackageManager pmObj = this.getPackageManager();
    try {
        PackageInfo piObj = pmObj.getPackageInfo(this.getPackageName(), PackageManager.GET_ACTIVITIES);
        sbObj.append(piObj.versionName);
    } catch (NameNotFoundException e) {
        Log.e("ERROR", "MainCalendar setCustomTitle NameNotFoundException", e);
    }
    tvCustomTitleVersion.setText(sbObj.toString());
    Log.d("DEBUG", "MainCalendar setCustomTitle End");
}

From source file:com.abewy.android.apps.klyph.app.MainActivity.java

private void updateContent(int selection) {
    if (selection != oldSelection) {
        Bundle bundle = new Bundle();
        bundle.putString(KlyphBundleExtras.ELEMENT_ID, KlyphSession.getSessionUserId());

        String className = classes.get(selection);

        if (className.equals("com.abewy.android.apps.klyph.fragment.Chat")) {
            PackageManager pm = getPackageManager();

            try {
                pm.getPackageInfo(MESSENGER_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
                Intent intent = getPackageManager().getLaunchIntentForPackage(MESSENGER_PACKAGE_NAME);
                startActivity(intent);/*  w  w w. ja  v  a2s.com*/
            } catch (NameNotFoundException e) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MESSENGER_PLAY_STORE_URI));
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                startActivity(intent);
            }
        } else {
            if (selection < navAdapter.getCount())
                setTitle(navAdapter.getItem(selection));
            else
                setTitle(KlyphSession.getSessionUserName());

            Fragment fragment = Fragment.instantiate(MainActivity.this, className, bundle);

            if (previousFragment != null)
                previousFragment.onSetToBack(this);

            FragmentTransaction tx = getFragmentManager().beginTransaction();

            tx.replace(R.id.main, fragment, FRAGMENT_TAG);
            tx.commitAllowingStateLoss();
            ((IKlyphFragment) fragment).onSetToFront(this);

            previousFragment = (IKlyphFragment) fragment;

            navAdapter.setSelectedPosition(selection);
            navAdapter.notifyDataSetChanged();

            oldSelection = selection;

            if (notificationsFragment != null)
                notificationsFragment.setHasOptionsMenu(false);
        }
    }
}

From source file:org.wso2.emm.agent.utils.CommonUtils.java

public static boolean isSystemAppInstalled(Context context) {
    PackageManager packageManager = context.getPackageManager();
    boolean systemAppInstalled;
    try {/*  ww w.  j  a va2s  . co  m*/
        packageManager.getPackageInfo(Constants.SYSTEM_SERVICE_PACKAGE, PackageManager.GET_ACTIVITIES);
        systemAppInstalled = true;
    } catch (PackageManager.NameNotFoundException e) {
        systemAppInstalled = false;
    }
    return systemAppInstalled;
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static boolean isPackageInstalled(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    try {//from   w  ww .  j a  v a  2s .co  m
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:com.abewy.android.apps.openklyph.app.MainActivity.java

private void updateContent(int selection) {
    if (selection != oldSelection) {
        Bundle bundle = new Bundle();
        bundle.putString(KlyphBundleExtras.ELEMENT_ID, KlyphSession.getSessionUserId());

        String className = classes.get(selection);

        if (className.equals("com.abewy.android.apps.openklyph.fragment.Chat")) {
            PackageManager pm = getPackageManager();

            try {
                pm.getPackageInfo(MESSENGER_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
                Intent intent = getPackageManager().getLaunchIntentForPackage(MESSENGER_PACKAGE_NAME);
                startActivity(intent);//from   ww w. j av  a2  s  .  c om
            } catch (NameNotFoundException e) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MESSENGER_PLAY_STORE_URI));
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                startActivity(intent);
            }
        } else {
            if (selection < navAdapter.getCount())
                setTitle(navAdapter.getItem(selection));
            else
                setTitle(KlyphSession.getSessionUserName());

            Fragment fragment = Fragment.instantiate(MainActivity.this, className, bundle);

            if (previousFragment != null)
                previousFragment.onSetToBack(this);

            FragmentTransaction tx = getFragmentManager().beginTransaction();

            tx.replace(R.id.main, fragment, FRAGMENT_TAG);
            tx.commitAllowingStateLoss();
            ((IKlyphFragment) fragment).onSetToFront(this);

            previousFragment = (IKlyphFragment) fragment;

            navAdapter.setSelectedPosition(selection);
            navAdapter.notifyDataSetChanged();

            oldSelection = selection;

            if (notificationsFragment != null)
                notificationsFragment.setHasOptionsMenu(false);
        }
    }
}

From source file:android.content.pm.PackageParser.java

public static PackageInfo generatePackageInfo(PackageParser.Package p, int gids[], int flags,
        long firstInstallTime, long lastUpdateTime, Set<String> grantedPermissions, PackageUserState state,
        int userId) {

    if (!checkUseInstalledOrHidden(flags, state)) {
        return null;
    }/*from  w ww .j  a  v a 2 s . c o m*/
    PackageInfo pi = new PackageInfo();
    pi.packageName = p.packageName;
    pi.splitNames = p.splitNames;
    pi.versionCode = p.mVersionCode;
    pi.baseRevisionCode = p.baseRevisionCode;
    pi.splitRevisionCodes = p.splitRevisionCodes;
    pi.versionName = p.mVersionName;
    pi.sharedUserId = p.mSharedUserId;
    pi.sharedUserLabel = p.mSharedUserLabel;
    pi.applicationInfo = generateApplicationInfo(p, flags, state, userId);
    pi.installLocation = p.installLocation;
    pi.coreApp = p.coreApp;
    if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
            || (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
        pi.requiredForAllUsers = p.mRequiredForAllUsers;
    }
    pi.restrictedAccountType = p.mRestrictedAccountType;
    pi.requiredAccountType = p.mRequiredAccountType;
    pi.overlayTarget = p.mOverlayTarget;
    pi.firstInstallTime = firstInstallTime;
    pi.lastUpdateTime = lastUpdateTime;
    if ((flags & PackageManager.GET_GIDS) != 0) {
        pi.gids = gids;
    }
    if ((flags & PackageManager.GET_CONFIGURATIONS) != 0) {
        int N = p.configPreferences != null ? p.configPreferences.size() : 0;
        if (N > 0) {
            pi.configPreferences = new ConfigurationInfo[N];
            p.configPreferences.toArray(pi.configPreferences);
        }
        N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
        if (N > 0) {
            pi.reqFeatures = new FeatureInfo[N];
            p.reqFeatures.toArray(pi.reqFeatures);
        }
        N = p.featureGroups != null ? p.featureGroups.size() : 0;
        if (N > 0) {
            pi.featureGroups = new FeatureGroupInfo[N];
            p.featureGroups.toArray(pi.featureGroups);
        }
    }
    if ((flags & PackageManager.GET_ACTIVITIES) != 0) {
        int N = p.activities.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.activities = new ActivityInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.activities.get(i).info.enabled)
                        num++;
                }
                pi.activities = new ActivityInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Activity activity = p.activities.get(i);
                if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_RECEIVERS) != 0) {
        int N = p.receivers.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.receivers = new ActivityInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.receivers.get(i).info.enabled)
                        num++;
                }
                pi.receivers = new ActivityInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Activity activity = p.receivers.get(i);
                if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_SERVICES) != 0) {
        int N = p.services.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.services = new ServiceInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.services.get(i).info.enabled)
                        num++;
                }
                pi.services = new ServiceInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Service service = p.services.get(i);
                if (service.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.services[j++] = generateServiceInfo(p.services.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_PROVIDERS) != 0) {
        int N = p.providers.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.providers = new ProviderInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.providers.get(i).info.enabled)
                        num++;
                }
                pi.providers = new ProviderInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Provider provider = p.providers.get(i);
                if (provider.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_INSTRUMENTATION) != 0) {
        int N = p.instrumentation.size();
        if (N > 0) {
            pi.instrumentation = new InstrumentationInfo[N];
            for (int i = 0; i < N; i++) {
                pi.instrumentation[i] = generateInstrumentationInfo(p.instrumentation.get(i), flags);
            }
        }
    }
    if ((flags & PackageManager.GET_PERMISSIONS) != 0) {
        int N = p.permissions.size();
        if (N > 0) {
            pi.permissions = new PermissionInfo[N];
            for (int i = 0; i < N; i++) {
                pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
            }
        }
        N = p.requestedPermissions.size();
        if (N > 0) {
            pi.requestedPermissions = new String[N];
            pi.requestedPermissionsFlags = new int[N];
            for (int i = 0; i < N; i++) {
                final String perm = p.requestedPermissions.get(i);
                pi.requestedPermissions[i] = perm;
                // The notion of required permissions is deprecated but for compatibility.
                pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
                if (grantedPermissions != null && grantedPermissions.contains(perm)) {
                    pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
                }
            }
        }
    }
    if ((flags & PackageManager.GET_SIGNATURES) != 0) {
        int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
        if (N > 0) {
            pi.signatures = new Signature[N];
            System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
        }
    }
    return pi;
}