Android: how to get the name of apk file programmatically?

android, apk, file

Solution

final PackageManager pm = getPackageManager();
String apkName = "example.apk";
String fullPath = Environment.getExternalStorageDirectory() + "/" + apkName;        
PackageInfo info = pm.getPackageArchiveInfo(fullPath, 0);

you can got it with:

info.versionCod

and

info.versionName

hope this help you

Problem

For some reasons, my app can be installed with different apk names. At launch, I would like to know what is the name of the apk file. Do you know how to do that ? Thanks !

Original source

Related problems