Java Code Examples for android.content.pm.PackageManager.getInstallerPackageName()

The following are Jave code examples for showing how to use getInstallerPackageName() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: buildAPKsSamples   File: MarketDetector.java   View Source Code Vote up 6 votes
public static int detect(Context c) {
	if (Build.VERSION.SDK_INT < 5)
		return APPSTORE;
	
	PackageManager pm = c.getPackageManager();
			
	String installer = pm.getInstallerPackageName(c.getPackageName());
	
	if (installer != null && installer.equals("com.android.vending")) 
		return MARKET;
	
	if (Build.MODEL.equalsIgnoreCase("Kindle Fire")) 
		return APPSTORE;

	try {
		if (pm.getPackageInfo("com.amazon.venezia", 0) != null) 
			return APPSTORE;
	} catch (NameNotFoundException e) {
	}
	
	return MARKET;
}
 
Example 2
Project: kognitivo   File: AttributionIdentifiers.java   View Source Code Vote up 5 votes
@Nullable
private static String getInstallerPackageName(Context context) {
    PackageManager packageManager = context.getPackageManager();
    if (packageManager != null) {
        return packageManager.getInstallerPackageName(context.getPackageName());
    }
    return null;
}
 
Example 3
Project: Brevent   File: VersionPreference.java   View Source Code Vote up 5 votes
static String getInstaller(Context context) {
    PackageManager packageManager = context.getPackageManager();
    String installer = packageManager.getInstallerPackageName(BuildConfig.APPLICATION_ID);
    if (!TextUtils.isEmpty(installer)
            && packageManager.getLaunchIntentForPackage(installer) != null) {
        return installer;
    } else {
        return null;
    }
}
 
Example 4
Project: Matrix-Calculator-for-Android   File: GlobalValues.java   View Source Code Vote up 5 votes
public void SetDonationKeyStatus() {

        if (BuildConfig.DEBUG) {
            Status = true;
            return;
            //if debug mode, avoid the advertisements and use pro features
        }
        try {
            PackageManager packageManager = getPackageManager();
            packageManager.getPackageInfo("com.softminds.matrixcalculator.pro.key", 0);
            //Key is Installed
            //Checking the Authenticity of the Key
            if (packageManager.checkSignatures(getPackageName(),
                    "com.softminds.matrixcalculator.pro.key")
                    == PackageManager.SIGNATURE_MATCH) {
                Log.d(TAG, "The Signature of Key Matched with Application");
                String manager = packageManager.getInstallerPackageName("com.softminds.matrixcalculator.pro.key");
                if (manager != null) {
                    //Status = true;
                    Log.d(TAG, manager);
                    if (Objects.equals(manager, "com.android.vending")) {
                        Status = true;
                    } else {
                        Status = false;
                        Toast.makeText(this, R.string.clear_warn_invalid_install, Toast.LENGTH_LONG).show();
                    }
                }
                //the Key is Genuine and was Installed from Play
            }
        } catch (Exception e) {
            Status = false;
        }
    }
 
Example 5
Project: XPrivacy   File: Util.java   View Source Code Vote up 5 votes
public static boolean hasMarketLink(Context context, String packageName) {
	try {
		PackageManager pm = context.getPackageManager();
		String installer = pm.getInstallerPackageName(packageName);
		if (installer != null)
			return installer.equals("com.android.vending") || installer.contains("google");
	} catch (Exception ex) {
		log(null, Log.WARN, ex.toString());
	}
	return false;
}
 
Example 6
Project: mobile-store   File: App.java   View Source Code Vote up 4 votes
private void setFromPackageInfo(PackageManager pm, PackageInfo packageInfo) {

        this.packageName = packageInfo.packageName;
        final String installerPackageName = pm.getInstallerPackageName(packageName);
        CharSequence installerPackageLabel = null;
        if (!TextUtils.isEmpty(installerPackageName)) {
            try {
                ApplicationInfo installerAppInfo = pm.getApplicationInfo(installerPackageName,
                        PackageManager.GET_META_DATA);
                installerPackageLabel = installerAppInfo.loadLabel(pm);
            } catch (PackageManager.NameNotFoundException e) {
                Log.w(TAG, "Could not get app info: " + installerPackageName, e);
            }
        }
        if (TextUtils.isEmpty(installerPackageLabel)) {
            installerPackageLabel = installerPackageName;
        }

        ApplicationInfo appInfo = packageInfo.applicationInfo;
        final CharSequence appDescription = appInfo.loadDescription(pm);
        if (TextUtils.isEmpty(appDescription)) {
            this.summary = "(installed by " + installerPackageLabel + ")";
        } else if (appDescription.length() > 40) {
            this.summary = (String) appDescription.subSequence(0, 40);
        } else {
            this.summary = (String) appDescription;
        }
        this.added = new Date(packageInfo.firstInstallTime);
        this.lastUpdated = new Date(packageInfo.lastUpdateTime);
        this.description = "<p>";
        if (!TextUtils.isEmpty(appDescription)) {
            this.description += appDescription + "\n";
        }
        this.description += "(installed by " + installerPackageLabel
                + ", first installed on " + this.added
                + ", last updated on " + this.lastUpdated + ")</p>";

        this.name = (String) appInfo.loadLabel(pm);
        this.icon = getIconName(packageName, packageInfo.versionCode);
        this.installedVersionName = packageInfo.versionName;
        this.installedVersionCode = packageInfo.versionCode;
        this.compatible = true;
    }
 
Example 7
Project: buildAPKsApps   File: AppRater.java   View Source Code Vote up 4 votes
/**
 * Should be called on every <code>Activity.onCreate()</code>. Checks if the
 * trial period is over and if so brings up a notification dialog.
 * 
 * @param ctx
 *          The application context.
 */
public static void appLaunched(Context ctx) {
	try {
		// Don't even bother if not installed from Google Play
		PackageManager pm = ctx.getPackageManager();
		String pn = ctx.getPackageName();
		String inst = pm.getInstallerPackageName(pn);
		if (inst == null || !(inst.startsWith("com.google")
				|| inst.startsWith("com.android"))) {
			return;
		}
	}
	catch (Exception exp) {
		Log.w("AppRater",exp);
		// Just bailout. Don't even try recovery.
		return;
	}

	SharedPreferences prefs = ctx.getSharedPreferences(PREFSFILE, 0);
	if (prefs.getBoolean("dontshowagain", false)) {
		return;
	}

	SharedPreferences.Editor editor = prefs.edit();

	// Increment launch counter
	long launch_count = prefs.getLong("launch_count", 0) + 1;
	editor.putLong("launch_count", launch_count);

	// Get date of first launch
	Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
	if (date_firstLaunch == 0) {
		date_firstLaunch = System.currentTimeMillis();
		editor.putLong("date_firstlaunch", date_firstLaunch);
	}
	editor.commit();

	// Wait at least n days before opening
	if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
		if (System.currentTimeMillis() >= date_firstLaunch
				+ (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
			showRateDialog(ctx);
		}
	}
}