Created
July 20, 2019 13:42
-
-
Save robot9706/f54ef31a54b70cad01803e73bc0a57a1 to your computer and use it in GitHub Desktop.
Checks if an Android app is installed from Google
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //https://stackoverflow.com/questions/48369912/check-if-an-application-is-installed-from-google-play | |
| protected static boolean installedFromMarket(WeakReference<? extends Context> weakContext) { | |
| boolean result = false; | |
| Context context = weakContext.get(); | |
| if (context != null) { | |
| try { | |
| String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName()); | |
| // if installer string is not null it might be installed by market | |
| if (!TextUtils.isEmpty(installer)) { | |
| result = true; | |
| // on Android Nougat and up when installing an app through the package installer (which HockeyApp uses itself), the installer will be | |
| // "com.google.android.packageinstaller" or "com.android.packageinstaller" which is also not to be considered as a market installation | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (TextUtils.equals(installer, INSTALLER_PACKAGE_INSTALLER_NOUGAT) || TextUtils.equals(installer, INSTALLER_PACKAGE_INSTALLER_NOUGAT2))) { | |
| result = false; | |
| } | |
| // on some devices (Xiaomi) the installer identifier will be "adb", which is not to be considered as a market installation | |
| if (TextUtils.equals(installer, INSTALLER_ADB)) { | |
| result = false; | |
| } | |
| } | |
| } catch (Throwable ignored) { | |
| } | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment