Created
August 15, 2020 19:40
-
-
Save AbreuY/33186b349e28e154fb9345aecb797cb6 to your computer and use it in GitHub Desktop.
Get current version code in android app
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
| static int getCurrentVersionCode(Activity activity) { | |
| try { | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | |
| return (int) activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).getLongVersionCode(); | |
| } else { | |
| //noinspection deprecation | |
| return activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionCode; | |
| } | |
| } catch (PackageManager.NameNotFoundException e) { | |
| Log.e(TAG, e.toString()); | |
| } | |
| return -1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment