Hello I am looking for the way to set the bitmap which are not in res directory. Actually I am getting that icon from the URL and want to set it in the notifica
I think you can't use directly the URL, but you can use the following statement, but only if you use a large icon.
This statement converts a URL into a BitMap:
Bitmap bitmap = getBitmapFromURL("Your URL");
public Bitmap getBitmapFromURL(String strURL) {
try {
URL url = new URL(strURL);
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, in your notification builder you can use the following code:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setLargeIcon(bitmap)
.setContentTitle(Util.notificationTitle)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(notificationMessage))
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
.setContentText(notificationMessage);
Don't forget the permissions in your Manifest: