I want to raise a notification showing an icon in the status bar - so far so good, but actually I would like this icon to be a 3 character String.
So my question is: Is
I have used a workaround and it worked properly for me.
First i convert the string to bitmap and then convert it to a drawable, here is the code:
byte [] encodeByte=Base64.decode(":",Base64.DEFAULT);
Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
Drawable d = new BitmapDrawable(bitmap);
Hope it helps!
try {
InputStream inputStream = new URL(Your imageWebAddress).openStream();
drawable = Drawable.createFromStream(inputStream, null);
inputStream.close();
}
catch (MalformedURLException ex) { }
catch (IOException ex) { }
layout.setBackground(drawable);
Short: No, you can't.
Long: The notification needs a R.drawable.something
for the icon and you can't create it on runtime.
you can make your own custom drawable that would work just like the textview widget except it is a drawable instead of a view. The textview class is just a container for the drawable that contains the text.
Have you looked at the API Demos > App > Notifications > Status Bar?
If you have limited number of String options (like Smileys) you can create drawables for each of those Strings.
No you can not, I thought you could use the same method as here: Combine image and text to drawable, but you can't, as the notification takes a drawable id, not a drawable object.