I have an application package name. Is there any way to get the icon, name of this application ? package name example: com.example.name
Drawable icon =getPackageManager().getApplicationIcon("ur_package");
Strign label = context.getPackageManager().getApplicationLabel("ur_package");
if you want to get installed app package name then this code will be helpful to you.
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);
Try something like:
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();
}
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)
{
//
}