1

I need to get the int id of my application icon. Is there any way I can do this?

I'm aware that there's GetApplicationIcon in PackageManager, but this returns a drawable. How can I get the Id of the drawable?

Drawable drawable = ApplicationContext.PackageManager.GetApplicationIcon(applicationInfo);

I was thinking of looping through all the resources in Android, but I'm not sure how, and I think it would be expensive. Any efficient way I can get the icon id?

EDIT: I understand that I can just easily get the resource id from R.drawable.myicon, but I was hoping to get the Id with the use of PackageManager or ApplicationContext.Resources.

EDIT #2: I got it. See my answer below.

nic
  • 2,125
  • 1
  • 18
  • 33

3 Answers3

3

R.drawable.ic_launcher (or other name you gave it) should represent the id you need.

Voicu
  • 16,921
  • 10
  • 60
  • 69
2

Okay, I got it.

Intent intent = context.PackageManager.GetLaunchIntentForPackage(context.PackageName);
ResolveInfo resolveInfo = context.PackageManager.ResolveActivity(intent, PackageInfoFlags.MatchDefaultOnly);
int appIcon = resolveInfo.IconResource;
nic
  • 2,125
  • 1
  • 18
  • 33
1

Well, since it's your application, you can just look in your manifest. Your icon appears in the <application> tag, in the android:icon attribute. Just look at that file and see what it says.

You don't need to program that, just do it yourself one time.

zmbq
  • 38,013
  • 14
  • 101
  • 171