Issue
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
Solution
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()
.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.