我有一个应用程序包名称。有什么方法可以获取此应用程序的图标、名称吗?包名示例:com.example.name
问问题
36088 次
4 回答
47
尝试类似:
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();
}
于 2013-01-19T19:14:43.283 回答
0
Drawable icon =getPackageManager().getApplicationIcon("ur_package");
Strign label = context.getPackageManager().getApplicationLabel("ur_package");
于 2015-10-19T14:30:51.550 回答
0
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)
{
//
}
于 2016-02-01T21:09:56.267 回答
0
如果您想获取已安装的应用程序包名称,那么此代码将对您有所帮助。
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> pkgAppsList = MainActivity.this.getPackageManager().queryIntentActivities( mainIntent, 0);
Log.i("InstalledAPK",pkgAppsList.toString());
for(int i=0;i<pkgAppsList.size();i++){
list.add(pkgAppsList.get(i).toString());
Log.e("PACKAGENAME",""+MainActivity.this.getPackageManager().getInstalledPackages(i).get(i).packageName);
}
ArrayAdapter<String> adapter=new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,list);
listView.setAdapter(adapter);
于 2018-01-19T12:06:50.080 回答