Is it possible to get icons from the server at run time? - android

I don't want to have some icons inside the application. Can I download icons from the server? And how can this be done? Maybe I need a cache for it.
Icons converted from svg to xml.

Yes,sure.. you can hit API and parse parameter named iconurl and put parameter in picasso.
Like this.
Picasso.with(context).load(your_iconurl).fit().into(holder.your_imageview);

Add below dependency in Gradle:
implementation 'com.squareup.picasso:picasso:2.71828'
Refer below sample code to load image into view:
String imageUri = "https://i.imgur.com/tGbaZCY.jpg";
ImageView ivBasicImage = (ImageView) findViewById(R.id.ivBasicImage);
Picasso.with(context).load(imageUri).into(ivBasicImage);
Reference:
http://square.github.io/picasso/
https://github.com/codepath/android_guides/wiki/Displaying-Images-with-the-Picasso-Library

Related

How can I retrieve an image using shared presences and show it in an image view in Android studio?

I'm trying to set an image in an image view in my activity but I don't know what the code is to do it.
I know how to do it but setting text into text view using this code
TextViewUser.setText( sharedaPrefManager.getInstance(this, ).get Username ().
I need how to do it but for an image.
I'm using volley and already get the image but I don't know how to put it in image view.
Thanks in advance
Once you get the image URL load it to the ImageView as follows
Try picasso library
Add to build.gradle
implementation 'com.squareup.picasso:picasso:2.71828'
Then
String imageUrl = "https://example.com/someimage.png"
Picasso.get().load(imageUrl)
.into(imageView);
You must be getting an image URL
so simply Use Glide
add this line to your app level build.gradle
dependencies {
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}
then Use something like this
// String imgUrl = ImageURL;
String imgUrl = sharedaPrefManager.getInstance(this).getImgae();
Glide.with(this).load(imgUrl).into(imageView);

Download Image from url and show in listview

I'm fetching title,data and url of the image. I'm storing url of the image in an arraylist. Now I want to download the images from these urls and show them in list view. I've tried multiple codes but none of them worked. If any of them can share any code snippet that would by really helpful. Thank you.
You can do this two ways:
1.Picasso
Add below library in gradle
implementation 'com.squareup.picasso:picasso:2.5.2'
Code :
Picasso.with(this).load("url").into(imageView);
2.Glide Library
Add below library in gradle
implementation 'com.github.bumptech.glide:glide:4.8.0'
Code to Set
Glide.with(this).load("url").into(imageview);
Import Picasso Or Glide in you're project :
Code for Picasso :
Picasso.get().load("url").into(imageView);
Code for Glide :
Glide.with(this).load("url").into(imageView);
All you have to do is import one of library and set image to imageholder in listview. Make sure you put condition while putting image to imageView.
Something like :
if(url != null){
Picasso.get().load("url").into(imageView);
}else{
Picasso.get().load(/*add any drawable or blank*/).into(imageView);
}
For showing Images in ImageView or ListView you can use Picasso and Glide library.
In Picasso like this:
Picasso.with(activity).load(ImageUrl).into(holder.productimage);
and in Glide like this:
Glide.with(this).load("url").into(imageView);

Android add shortcut icon from a url instead from drawable resources

I have an app where i am adding shortcut. I want to add shortcut icon image from URL path(images are stored on server and can be change) instead of using Drawable but i don't know how to do that. I tried to find a lot on this community. Any help?
If the term used "shortcut icon" is a view or its descendants such as ImageView, then you can set the image, your application receive from the server by doing this :
add dependency to your app.gradle file :
compile 'com.github.bumptech.glide:glide:3.7.0'
and in the activity you can use this method to set the image to the imageview your app receive from the server :
ImageView imageView = (ImageView) findViewById(R.id.image_view);
Glide.with(imageview.getContext()).load("https://url").error(R.drawable.not_found).centerCrop().into(imageview);
What you could do is first download that icon and store locally and then take that file path and use
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, UUID.randomUUID().toString())
.setIntent(intent) // !!! intent's action must be set on oreo
.setShortLabel(lable)
.setIcon(IconCompat.createWithAdaptiveBitmapContentUri(filePath)).build();
ShortcutManagerCompat.requestPinShortcut(this, shortcutInfo, null);
add this in your build.gradle
compile 'com.squareup.picasso:picasso:2.5.2'
now you can load the image using following code
Picaso.with(this).load(urlHere).into(imageView);

show gif image in imageview Android

A very strange behaviour, while writing code for showing GIF image in image-view.
what i am doing is
InputStream is = this.getResources().openRawResource(R.drawable.logo);
logo is gif image that is in the drawable folder.
when I write that line of code in Eclipse , image loads successfully but when I import that code on Android Studio What I am seeing is an error on R.drawable.logo
and the error is
Expected Resource of type raw
supplying the wrong type of resource identifier. For Example when calling Resources.getString(int id), You should be passing R.string.something not R.drawable.something
one code runs on Eclipse not on Android Studio
I am sure that no problem with the imports.
After doing some R&D i have found a work-around for that
and that is instead of creating drawable folder and put that image into it
create assets folder in main/src/assests and paste that image and then open Input steam.
InputStream is = context.getAssets().open("logo.gif");
that worked for me but sill dont know the answer why
InputStream is = this.getResources().openRawResource(R.drawable.logo);
was not working.
you can try using ion https://github.com/koush/ion#load-an-image-into-an-imageview is a nice library for load images and support gif from local store , resorces or from Url.
Simple solution is using Glide library
compile 'com.github.bumptech.glide:glide:4.3.1'
And Load your ImageView
Glide.with(YourActivity.this).load(R.drawable.your_gif).into(yourImageView);

displaying image in the imageview directly from the internet

I want to load an image which is located at the url "http://www.Karnatakatourism.org/mm/slide/chickmaglur_home.jpg" onto the imageview in Android.
Can anyone help me with the code to do the same?
You can use android query lib. http://code.google.com/p/android-query/wiki/ImageLoading
You just need to write
aq.id(R.id.imageview_profilee).image("your path");
You can use this one...
There many libs to do this, You can use Picasso.
Here an example of usage:
Picasso.with(context).load("http://www.karnatakatourism.org/mm/slide/chickmaglur_home.jpg").into(imageView);
Or you can use Universal Image Loader class
in which you can use by this one.
imageLoader.displayImage("http://www.karnatakatourism.org/mm/slide/chickmaglur_home.jpg", imageView, options);

Categories

Resources