我正在使用下面的代码获取我安装的应用程序的名称,并使用它们来查看此应用程序是否有可用的更新。
但有时提供的名称不正确(MX Speler而不是MX Player),因此找不到任何更新。
有没有我可以/应该使用的更好的代码?
{
final PackageInfo pi = installedInfo != null ? installedInfo : downloadedInfo;
final PackageManager pm = getApplicationContext().getPackageManager();
ApplicationInfo ai;
try {
ai = pm.getApplicationInfo(pi ??, 0); //How to set the name of the installed application?
} catch (final NameNotFoundException e) {
ai = null;
}
final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");
System.out.println("Application name : "+ applicationName);
}发布于 2015-01-04 02:36:28
您不应该使用labels,因为它可能在每种语言中都不同,或者在每次更新时都会更改。您应该只依赖应用程序的 id (packageId),因为此id在应用程序的整个生命周期中保持不变。
https://stackoverflow.com/questions/27758056
复制相似问题