Android Context Check isInstalledThroughPlayStore(final Context context)

Here you can find the source of isInstalledThroughPlayStore(final Context context)

Description

Check whether the application is installed through the Play Store.

License

Apache License

Parameter

Parameter Description
context Context

Return

true when the app is installed through the Play store, otherwise false

Declaration

public static boolean isInstalledThroughPlayStore(final Context context) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import android.content.Context;

import android.content.pm.PackageManager;

public class Main {
    /**//from w  ww  .  j a  v a  2s. c  om
     * Check whether the application is installed through the Play Store.
     *
     * @param context Context
     * @return true when the app is installed through the Play store, otherwise false
     */
    public static boolean isInstalledThroughPlayStore(final Context context) {
        final PackageManager packageManager = context.getPackageManager();
        final String packageInstallerName = packageManager
                .getInstallerPackageName(getPackageName(context));
        if ("com.android.vending".equals(packageInstallerName)) {
            // App is installed through the Play Store
            return true;
        }
        return false;
    }

    /**
     * Get the application package name.
     *
     * @param context Context
     * @return package name
     */
    public static String getPackageName(final Context context) {
        return context.getPackageName();
    }
}

Related

  1. isFree(Context context)
  2. isGPRSAvailable(Context context)
  3. isGoogleAccountPresent(Context ctx)
  4. isGpsEnabled(Context context)
  5. isHeadsetPluggedIn(Context context)
  6. isLandscape(Context context)
  7. isLandscape(final Context context)
  8. isLocationEnabledGPS(Context c)
  9. isMobile(Context context)