How to load an ImageView by URL in Android?
Anyway people ask my comment to post it as answer. i am posting.
URL newurl = new URL(photo_url_str);
mIcon_val = BitmapFactory.decodeStream(newurl.openConnection().getInputStream());
profile_photo.setImageBitmap(mIcon_val);
Load image from url
URL url = new URL("http://image10.bizrate-images.com/resize?sq=60&uid=2216744464");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);
Android : How to set an image to an imageview from a url programatically
The easiest way to do it is by using something like Picasso or Glide:
Picasso.with(getContext()).load(imgUrl).fit().into(contentImageView);
you can add picasso library in your gradle: compile 'com.squareup.picasso:picasso:2.5.2'
How to load Image into ImageView from Url using Glide v4.0.0RC1
If you are using Glide v4.0.0-RC1 then you need to use RequestOptions
to add the placeholder, error image and other option. Here is an working example
RequestOptions options = new RequestOptions()
.centerCrop()
.placeholder(R.mipmap.ic_launcher_round)
.error(R.mipmap.ic_launcher_round);
Glide.with(this).load(image_url).apply(options).into(imageView);
Android how to set image to imageview from url
try this
1.you can user Glide library to load image from url look the below code it can help you in simple way
compile this library
compile 'com.github.bumptech.glide:glide:4.0.0-RC0'
than load image like this
Glide.with(HomeClass.this)
.load(url)
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.dontAnimate()
.into(imageview);
2 .try this if you dont want to use third party library
new DownloadImage(imamgeview).execute(url);
create a Async Task
public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImage(ImageView bmImage) {
this.bmImage = (ImageView ) bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.d("Error", e.getStackTrace().toString());
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
i hope that it will work in your case
Load ImageView from URL into RemoteView of a Home Screen Widget
Just need to do it synchronously. This seems to work fine:
try {
Bitmap bitmap = Glide.with(context)
.asBitmap()
.load(widgetItems.get(position).image_url)
.submit(512, 512)
.get();
rv.setImageViewBitmap(R.id.widget_item_image, bitmap);
} catch (Exception e) {
e.printStackTrace();
}
Related Topics
Android Accelerometer Accuracy (Inertial Navigation)
Android Check Internet Connection
Firebase Onmessagereceived Not Called When App in Background
Determining the Current Foreground Application from a Background Task or Service
Communicating Between a Fragment and an Activity - Best Practices
How to Check a Certain Data Already Exists in Firestore or Not
Viewpager and Fragments - What's the Right Way to Store Fragment'S State
What Is the List of Supported Languages/Locales on Android
Getting the Screen Density Programmatically in Android
Android: Listview Elements With Multiple Clickable Buttons
Java.Lang.Outofmemoryerror: Bitmap Size Exceeds Vm Budget - Android
Comparison of Android Networking Libraries: Okhttp, Retrofit, and Volley
How to Manually Include External Aar Package Using Gradle For Android
How to Get Zoom Functionality For Images
Android Action_Image_Capture Intent
Multiple Dex Files Define Landroid/Support/V4/Accessibilityservice/Accessibilityserviceinfocompat