Crocodile
Crocodile

Reputation: 5855

How to find out the path& filename to the application launcher icon declared in Android manifest

I figured out that I can reuse my app's launcher icon inside my app, which is declared in the manifest as a launcher icon. I am doing this by simply calling the icon image from a layout xml file with the same file name and path as declared in the Android manifest.

e.g.: 
  <ImageView
  ...
  android:src="@drawable/ic_launcher">
  </ImageView>

The problem is: that if in the future I changed the icon's name/path in the manifest file, the code in the layout file would also need to be updated. Also, I would like to be able to reuse this piece of layout code in my next app without worrying about what filename & path has been declared in the manifest for the icon.

Can I find out from my code the name&path declared in the manifest file for the launcher icon? This would allow me to read the manifest first then use the same name&path from the layout file.

Upvotes: 0

Views: 841

Answers (1)

chiuki
chiuki

Reputation: 14700

You can do this in your Activity:

String packageName = getPackageName();
PackageManager pm = getPackageManager();
Drawable icon = pm.getApplicationIcon(packageName);
imageView.setImageDrawable(icon);

Upvotes: 1

Related Questions