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?