请我将android代码转换为应用程序名称(假设我已经有了包名,例如String name =" com.skgames.trafficrider")
答案 0 :(得分:0)
将包名称添加到此函数并获取AppName(应用程序标签)
public String appName(String pack){
String Name = null;
try{
PackageManager packManager = context.getPackageManager();
ApplicationInfo app = context.getPackageManager().getApplicationInfo(pack, 0);
Name = packManager.getApplicationLabel(app).toString();
}
catch(Exception e){
e.printStackTrace();
}
return Name;
}
答案 1 :(得分:0)
尝试使用下一个代码:
ApplicationInfo ai;
try {
ai = pm.getApplicationInfo("com.skgames.trafficrider", 0);
} catch (final NameNotFoundException e) {
ai = null;
}
final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");