1

I need to set the notification image icon dynamically , whose name is passed to my class dynamically. For that , I need to set the builder.setSmallIcon(int res_id). I googled it , but people have used the example of setDrawableImage() I have seen this post , and accordingly implemented in my code.

   //blah blah lines of code
   String uri = "@drawable/a";
   int imageResource = con.getResources().getIdentifier(uri,null, con.getPackageName());
   Drawable res = con.getResources().getDrawable(imageResource);
   builder.setSmallIcon(res);
   //blah blah code lines

Of course, this shows error because setSmallIcon() requires integer to be passed to it. con is the context passed to my constructor. I have seen How to set the image from drawable dynamically in android? post

Community
  • 1
  • 1
lazy rabbit
  • 1,036
  • 3
  • 11
  • 28

1 Answers1

1

Of course, this shows error because setSmallIcon() requires integer to be passed to it.

You already have the desired integer. You named it imageResource. Pass imageResource to setSmallIcon().

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367