Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;

import android.content.pm.PackageManager;

public class Main {
    /**
     * 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();
    }
}