2

I am trying to download an image from a URL and then post a notification in the notification drawer with that image. I am operating in the context of an IntentService, so I am using simple synchronous image fetching:

public Bitmap getBitmapFromURL(String src) {
  try {
    java.net.URL url = new java.net.URL(src);
    HttpURLConnection connection = (HttpURLConnection) url
        .openConnection();
    connection.setDoInput(true);
    connection.connect();
    InputStream input = connection.getInputStream();
    Bitmap myBitmap = BitmapFactory.decodeStream(input);
    return myBitmap;
  } catch (IOException e) {
    e.printStackTrace();
    return null;
  }
}

Now that I have the image downloaded, how would I go about using it for a notification? The problem is that NotificationCompat.Builder.setSmallIcon(int) takes an integer ID. For example, something like R.drawable.my_cool_image.

Since I downloaded my image dynamically from the web, I do not have an ID for it. How would I use it as the notification icon?

  • http://stackoverflow.com/questions/15738800/how-to-add-a-dynamic-image-instead-of-notification-icon-in-android Does this answer your question? – stonecompass Apr 20 '15 at 21:00

1 Answers1

1

you cannot set small icons from downloaded images, only the big icon in the actual notification bar using .setLargeIcon(myBitmap);

Tomer Shemesh
  • 10,278
  • 4
  • 21
  • 44