Reputation: 5542
I'm trying to get an icon of the installed app. Using the following way, I'm getting the error:
The method getContext() is undefined for the type MainActivity
try{
String pkg = "com.app.my";//your package name
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
imageView.setImageDrawable(icon);
}
catch (PackageManager.NameNotFoundException ne) {
}
It would be very helpful if someone could guide me. Thanks in advance!!
Upvotes: 1
Views: 1408
Reputation: 539
Activity
class extends Context
.So just call getContext();
This will make use of the activities layout defined context.
Upvotes: 0
Reputation: 1006869
Delete getContext()
. Activity
extends Context
. Just call getPackageManager().getApplicationIcon(pkg)
.
Upvotes: 2