从包名获取应用程序信息

我有一个应用程序包名称。 有什么办法可以得到这个应用程序的图标,名称? 包名称示例:com.example.name

Solutions Collecting From Web of "从包名获取应用程序信息"

尝试像这样:

try { ApplicationInfo app = this.getPackageManager().getApplicationInfo("com.example.name", 0); Drawable icon = packageManager.getApplicationIcon(app); String name = packageManager.getApplicationLabel(app); return icon; } catch (NameNotFoundException e) { Toast toast = Toast.makeText(this, "error in getting icon", Toast.LENGTH_SHORT); toast.show(); e.printStackTrace(); } 
 Drawable icon =getPackageManager().getApplicationIcon("ur_package"); Strign label = context.getPackageManager().getApplicationLabel("ur_package"); 
 String PackgeNameApp = "com.test.icon"; String name="NULL"; try { ApplicationInfo app = this.getPackageManager().getApplicationInfo(PackgeNameApp, 0); Drawable icon = getPackageManager().getApplicationIcon(app); name = getPackageManager().getApplicationLabel(app).toString(); } catch (PackageManager.NameNotFoundException e) { // }