How to Get The Application's Icon from The Package Name

How can I get the application's icon from the package name?

Try this:

try
{
Drawable icon = getContext().getPackageManager().getApplicationIcon("com.example.testnotification");
imageView.setImageDrawable(icon);
}
catch (PackageManager.NameNotFoundException e)
{
e.printStackTrace();
}

Get the name, icon and package name of all the installed applications in android

Please use the below code and directions:

//check this code with some hard work then you will rock
List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);

ArrayList<AppInfo> res = new ArrayList<AppInfo>();
for(int i=0;i<apps.size();i++) {
PackageInfo p = apps.get(i);

AppInfo newInfo = new AppInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
}

class AppInfo {
String appname = "";
String pname = "";
String versionName = "";
int versionCode = 0;
Drawable icon;

}

For more information try these links:
http://javatechig.com/android/how-to-get-list-of-installed-apps-in-android http://developer.android.com/reference/android/content/pm/PackageManager.html

How to get the application icon?

try this

try {
String pkg = "com.simple.app";//your package name
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
imageView.setImageDrawable(icon);
} catch (PackageManager.NameNotFoundException ne) {
}

PackageManager not returing application's icon

To get the icons you should use both class & package names instead of only using the package name. If the app supports changing icons or has more than one launcher activity this works much better.

fun getIcon(context: Context, packageName: String, className: String): Drawable? {
var drawable: Drawable? = null
try {

val intent = Intent(Intent.ACTION_MAIN)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.setClassName(packageName, className)
drawable = context.packageManager.getActivityIcon(intent)

} catch (e: Exception) {
try {
drawable = context.packageManager.getApplicationIcon(packageName)
} catch (e: Exception) {
e.printStackTrace()
}
}
return drawable
}

This function returns the icon drawable or returns null if it fails. It tries to get the icon using both package and class names at first but if it fails it uses only package name. You can just use the package name one if you don't want to use the class name as well.

If it's still just catching the exception every time and you know the app is installed, you probably lack some permissions. You can also try again with targetSdkVersion 29 instead of targetSdkVersion 30 since 30 adds some limitations to this kind of functions but I am not sure if those affect getting the icons as well.

Application Name And Application Icon from Application Package Name In Android

First get the instance of package manager:

PackageManager packageManager = getPackageManager();

Now for getting App name and App icon via ApplicationInfo instance:

String appName = applicationInfo.loadLabel(packageManager)

Drawable appIcon = applicationInfo.loadIcon(packageManager)

Is there anyway to get android app icon, app name and app description using app package name?

If you want to provide a UI for customers to search apps, upload private apps and web apps, and organize apps. I would suggest checking out the Managed Google Play iFrame.

You can get the app name, app title, etc. by using applications.get() method. This method returns an Applications resource. Unfortunately, app info and icon isn’t included in the applications resource but there may be other APIs available outside Android Management API that return these fields.



Related Topics



Leave a reply



Submit