I try to download image from url with help of picasso.But i cant do. i spend time in this more than two days. I tried async task that also failed. i tried alot. Please anyone help me.
protected static void postNotification(Intent intentAction, Context context,String msg,String url){
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intentAction, Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL);
/* ImageDownloaderTask image = new ImageDownloaderTask();
image.execute(url);*/
Bitmap bitmapImage = retriveImage(url,context); //here only i want get that image.
Log.d("Bitmap", String.valueOf(bitmapImage));//Its print only null
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.tapn)
.setContentTitle("Welcome!")
.setContentText(msg)
.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmapImage))
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true)
.getNotification();
mNotificationManager.notify(R.string.notification_number, notification);
}
private static Bitmap retriveImage(String url,Context c) {
CacheTarget cacheTarget = new CacheTarget();
Picasso.with(c)
.load(url)
.into(cacheTarget);
return cacheTarget.getCacheBitmap();
}
private static class CacheTarget implements Target {
private Bitmap cacheBitmap;
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
cacheBitmap = bitmap;
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
public Bitmap getCacheBitmap() {
return cacheBitmap;
}
}
Thanks in advance!