- Home /
Access app_icon from an Android Plugin
Just like the title says. I need to access the app_icon from inside my android plugin.
I tried just using R.drawable.app_icon, but that doesn't work.
I then tried some code I found:
public int getResourseIdByName(String packageName, String className, String name) {
int id = 0;
try {
for (int i = 0; i < Class.forName(packageName + ".R").getClasses().length; i++) {
if(Class.forName(packageName + ".R").getClasses()[i].getName().split("\\$")[1].equals(className)) {
if(Class.forName(packageName + ".R").getClasses()[i] != null)
id = Class.forName(packageName + ".R").getClasses()[i].getField(name).getInt(Class.forName(packageName + ".R").getClasses()[i]);
break;
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
return id;
}
I tried passing in my package name from the plugin and also the package name for my whole unity app. Neither worked.
Can someone give me some sample for for accessing the app_icon from inside my plugin?
Did you find how to access the icon? I'm having exactly the same problem here.
No answer yet and I have not figured it out. If you find something please let me know.
Answer by Riacosta · Apr 08, 2013 at 05:42 PM
In order to access the current App Icon you usually need the Int value of the resource (which normally store at R.Drawable.icon var) the Int value to the icon is: 0x7f020000 Use that to access the resource instead the yourpackage.R.Drawable.icon. At least it work for me! :D
Your saying just use the actual int value. I will give that a try, but it seems a little like a bad idea because what if it changes? That is why we use named pointers in the .R file in the first place. It seems like there should be a way to get those in code.
I know it's not a good practice I but needed it to work. It's something!
Answer by Takafumi · Oct 10, 2013 at 07:43 AM
This works.
Resources res = getResources();
int icon = res.getIdentifier("app_icon", "drawable", getPackageName());