How to get an image resource by it's name in android?

With Resources.getIdentifier() method we can get the resource id by its name.

If we know drawable name then we can get drawable id by 

int resId = getResources().getIdentifier("Name of Resource", "drawable", mApplicationContext.getPackageName());

 

If we know color name then we can get color id by 

int resId = getResources().getIdentifier("Name of Resource", "color", mApplicationContext.getPackageName());