Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Get VersionName in Fragment

How do I get the versionName in a Fragment? The code below does not function:

PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;
like image 346
jyoonPro Avatar asked Jan 10 '23 15:01

jyoonPro


1 Answers

try this

    PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
    version = pInfo.versionName;

It's working fine.

like image 169
M D Avatar answered Jan 16 '23 08:01

M D