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 ?
Th
The apk or app name can be retrieved using package manager. According to alex's answer here - https://stackoverflow.com/a/30348666/2026280
Assuming you have the path of the apk file.
public static String getAppLabel(PackageManager pm, String pathToApk) {
PackageInfo packageInfo = pm.getPackageArchiveInfo(pathToApk, 0);
if (Build.VERSION.SDK_INT >= 8) {
// those two lines do the magic:
packageInfo.applicationInfo.sourceDir = pathToApk;
packageInfo.applicationInfo.publicSourceDir = pathToApk;
}
CharSequence label = pm.getApplicationLabel(packageInfo.applicationInfo);
return label != null ? label.toString() : null;
}