'Android Version Textview Writer

Is there another method to get version and is it healthy to get version this way?

String appName=getResources().getString(R.string.app_name);
String versionName=BuildConfig.VERSION_NAME;
String versionCode=String.valueOf(BuildConfig.VERSION_CODE);
Toast.makeText(getContext(),"App Name : "+appName+" version Name : "+versionName+"versionCode : "+versionCode,Toast.LENGTH_LONG).show();


Solution 1:[1]

You can use this method of mine ->

private String getCurrentVersion() {
    PackageManager pm = this.getPackageManager();
    try {
        PackageInfo pInfo = pm.getPackageInfo(this.getPackageName(), 0);
        return pInfo.versionName;
    } catch (PackageManager.NameNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        return "0.0";
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mahabub Karim