public static int getAppVersionCode(Context context) { return getApplicationInfo(context).getVersionCode(); }
public static String getAppVersionName(Context context) { return getApplicationInfo(context).getVersionName(); }
/** * Returns <code>true</code> is the app is running in a debug mode */ public static boolean isAppDebuggable(Context context) { return getApplicationInfo(context).isDebuggable(); }
public static AppRelease generateCurrentAppRelease(Context context, ApptentiveInternal apptentiveInternal) { AppRelease appRelease = new AppRelease(); String appPackageName = context.getPackageName(); int themeOverrideResId = context.getResources().getIdentifier("ApptentiveThemeOverride", "style", appPackageName); ApplicationInfo applicationInfo = RuntimeUtils.getApplicationInfo(context); appRelease.setAppStore(Util.getInstallerPackageName(context)); appRelease.setDebug(applicationInfo.isDebuggable()); appRelease.setIdentifier(appPackageName); if (apptentiveInternal != null) { appRelease.setInheritStyle(apptentiveInternal.isAppUsingAppCompatTheme()); } appRelease.setOverrideStyle(themeOverrideResId != 0); appRelease.setTargetSdkVersion(String.valueOf(applicationInfo.getTargetSdkVersion())); appRelease.setType("android"); appRelease.setVersionCode(applicationInfo.getVersionCode()); appRelease.setVersionName(applicationInfo.getVersionName()); return appRelease; }
public synchronized static @NonNull ApplicationInfo getApplicationInfo(Context context) { if (context == null) { throw new IllegalArgumentException("Context is null"); } if (cachedApplicationInfo == null) { // cache the value once (since it won't change while the app is running) try { PackageManager packageManager = context.getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); android.content.pm.ApplicationInfo ai = packageInfo.applicationInfo; boolean debuggable = ai != null && (ai.flags & android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) != 0; int targetSdkVersion = ai != null ? ai.targetSdkVersion : 0; cachedApplicationInfo = new ApplicationInfo(packageInfo.versionName, packageInfo.versionCode, targetSdkVersion, debuggable); ApptentiveLog.v("Resolved application info: %s", cachedApplicationInfo); } catch (Exception e) { ApptentiveLog.e(e, "Exception while getting app info"); logException(e); cachedApplicationInfo = ApplicationInfo.NULL; } } return cachedApplicationInfo; }