0
피카소의 도움으로 URL에서 이미지를 다운로드하려고합니다.하지만 할 수 없습니다. 나는 2 일 이상이 시간을 보낸다. 나는 또한 실패한 비동기 작업을 시도했다. 나는 많이 시도했다. 제발 도와주세요.피카소를 사용하여 URL에서 이미지를 다운로드하는 방법
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;
}
}
미리 감사드립니다.
가능한 중복 [다운로드 피카소를 사용하여 저장 이미지 (http://stackoverflow.com/questions/27729976/download- 도움이 될 것입니다 and-save-images-using-picasso) –
다른 질문 .. – hikoo
그 질문에 대한 답변도 귀하의 질문에 대한 답변을 제공합니다. 그것은 단지 ListView 그 질문에 액세스 할 수 있습니다 ..하지만 그건 중요하지 않습니다 주된 목적은 이미지를 다운로드하는 것입니다 .. !! –