Example usage for android.content Context getPackageManager

List of usage examples for android.content Context getPackageManager

Introduction

In this page you can find the example usage for android.content Context getPackageManager.

Prototype

public abstract PackageManager getPackageManager();

Source Link

Document

Return PackageManager instance to find global package information.

Usage

From source file:Main.java

public static String getVersionName(Context context) {
    PackageManager pm = context.getPackageManager();
    String versionName = "";
    try {//from ww w . j  av  a  2s  .  c o m
        PackageInfo info = pm.getPackageInfo(context.getPackageName(),
                PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
        if (null != info) {
            versionName = info.versionName;
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return versionName;

}

From source file:Main.java

private static PackageInfo getPackageInfo(Context context) throws NameNotFoundException {
    return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
}

From source file:Main.java

public static void bootApp(Context context, String activityName) {
    Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(activityName);
    context.startActivity(launchIntent);
}

From source file:Main.java

public static PackageInfo getPackageInfo(Context context) {
    try {/*  w  w  w  .j a v a 2s.  co m*/
        return context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_CONFIGURATIONS);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

/**
 * Utility method to check if a shortcut can be added to the home screen.
 * @param context Context used to get the package manager.
 * @return if a shortcut can be added to the home screen under the current profile.
 */// w w  w . ja  v  a 2s. c o m
// TODO(crbug.com/635567): Fix this properly.
@SuppressLint("WrongConstant")
public static boolean isAddToHomeIntentSupported(Context context) {
    PackageManager pm = context.getPackageManager();
    Intent i = new Intent(INSTALL_SHORTCUT);
    List<ResolveInfo> receivers = pm.queryBroadcastReceivers(i, PackageManager.GET_INTENT_FILTERS);
    return !receivers.isEmpty();
}

From source file:Main.java

@NonNull
public static List<ResolveInfo> getResolution(@NonNull Context context, @NonNull Intent intent) {
    return context.getPackageManager().queryIntentActivities(intent, 0);
}

From source file:Main.java

public static void startOtherApp(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    Intent launcherIntent = pm.getLaunchIntentForPackage(packageName);
    context.startActivity(launcherIntent);
}

From source file:Main.java

public static boolean isPackageInstalled(Context context, String packagename) {
    try {/*w  w w . ja  v  a  2 s.  co  m*/
        context.getPackageManager().getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

/**
 * Restart application (just relauch the first page of package)
 *
 *
 * @param context Context/*from w ww. ja v  a2s  . com*/
 */
public static void restartApplication(Context context) {
    final Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);
}

From source file:Main.java

/**
 * @return true if this device has Amazon Market App installed
 *//*from w  ww  .  j a  va  2 s .c o  m*/
public static boolean hasAmazonMarketApp(Context context) {
    try {
        context.getPackageManager().getPackageInfo("com.amazon.venezia", 0);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}