Show .gif from Firebase Storage link - android

I have link in my Firebase Storage on .gif file
String gifUrl = "https://firebasestorage.googleapis.com/v0/b/rokitskiydev-a18ca.appspot.com/o/WF%2F10-16-02-Digital-15.gif?alt=media&token=0354f6e6-4292-4911-9302-49281d293a80";
I try use Picasso and Glide. But I can show only image of this gif.
GlideApp.with(context).load(gifUrl).into(ImageView);
If i get another link, an example http://i.imgur.com/1ALnB2s.gif it's OK!
How can I do this?

Get the downloadUrl of the gif and then use that to load the gif with Glide.
ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(downloadUrl).into(imageViewTarget);
For newer versions of Glide try this:
Glide.with(context)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.loading2)
.crossFade()
.into(imageView);

As Glide Documentation says,
You can use .asGif() to force the library to load an animated gif and fail if it is not :
Glide.with(activity).load(gifUrl).asGif().into(view);
try this
Check the doc: https://futurestud.io/tutorials/glide-displaying-gifs-and-videos
also as FirebaseDoc says you can do this to load an image/gif with glide
first declare this in your build.gradle
dependencies {
// FirebaseUI Storage only
compile 'com.firebaseui:firebase-ui-storage:0.6.0'
}
then
this to load your image with firebase
// Reference to an image file in Firebase Storage
StorageReference storageReference = ...;
// ImageView in your Activity
ImageView imageView = ...;
// Load the image using Glide
Glide.with(this /* context */)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(imageView);
if you need the url of your image/gif file, you can do this
storageRef.child("your/firebase/imagepath.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png'
Uri downloadUri = taskSnapshot.getMetadata().getDownloadUrl();
generatedFilePath = downloadUri.toString(); /// The string(file link) that you need
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception exception) {
// Handle any errors
}
});

Related

Share file using Glide

I'm trying to share GIF file. I want to share it via any social networking apps, I have a problem with file name. I don't how to get name file. This is my code:
llsetwallpapers.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// set as wallpapers
lt.setText("Please Wait ...");
lt.setTranslationY(100);
lt.show();
Glide.with(getApplicationContext())
.load(url)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap resource, GlideAnimation<?super Bitmap> glideAnimation) {
File file = new File file = new File(getApplicationContext().getExternalCacheDir() , namefile)
file.setReadable(true);
Uri uri = Uri.fromFile(file);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/gif");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share with"));
}
});
}
});
The problem you are trying to solve is discussed at github issues, where RĂ³bert Papp has provided an example implementation for sharing a file downloaded by Glide.
The key part for you - is to get a reference to the File. That can be done with downloadOnly():
File file = Glide
.with(context)
.load(url)
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.get()
Having a File, you can use FileProvider API in order to share the file.

get image with picasso based on userId firebase

I am trying to do the image upload and download for a user profile, when I save a photo I save it with the userId so I can replace it everytime he changes his photo, now what I need is to get that photo with picasso, the thing is, I don't know how to get the photo, it can have different formats and other stuffs like jpeg, png, I just want to get the image when the userID match, I tried this:
storageRef = storage.getReferenceFromUrl("gs://friendlymanager-3b7a2.appspot.com");
Picasso.with(UserSettings.this).load(storageRef + "/Photos/" + userId).into(userImage);
my userImage is my imageView, i don't get any erros just a blank image, i already have a photo for the specific user.
Any help?
you will have to get download link like this,
StorageReference storageRef = storage.getReference().child("users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child(FirebaseAuth.getInstance().getCurrentUser().getUid());//reach out to your photo file hierarchically as stored on firebase
storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
Log.e("URI", uri.toString());
Glide.with(SaveUserActivity.this).load(uri).into(profile_image);
url = uri.toString();
}
});
Consider using Firebase-UI Android library which gives you ability to load images from storage ref directly. In your case it would look something like this
I'm not sure if Picasso is supported but you can use Glide
for example:
mStorageRef = FirebaseStorage.getInstance().getReference();
Glide.with(this /* context */)
.using(new FirebaseImageLoader())
.load(mStorageRef + "/Photos/" + userId)
.error(R.drawable.default)
.into(imageView);
You should use getDownloadUrl() while fetching images from Firebase storage using Picasso OR glide etc.

Image from StorageReference Firebase-Android

TextView myUsername=(TextView) findViewById(R.id.user);
myProfile=(ImageView) findViewById(R.id.photo);
Bundle bundleObject=getIntent().getExtras();
myAccount=(Account) bundleObject.getSerializable("account");
myUsername.setText(myAccount.get_username());
StorageReference profile =
FirebaseStorage.getInstance()
.getReference().child("profiles").child(myAccount.getUID()).child("profile");
profile.getDownloadUrl().addOnSuccessListener(Profile.this, new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
myProfile.setImageURI(uri);
}
});
I'm trying to put the image from the Firebase Storage in the ImageView but is not showing and I don't have any error . What I'm doing wrong?
ImageView doesn't load images from the internet itself - and the URL retrieved from Storage is a regular HTTPS one. The setImageURI method is for loading from the local file system.
You can use a library like Glide or Picasso to do the image loading - if you take a look at FirebaseUI, you'll find a helpful integration that includes caching: https://github.com/firebase/FirebaseUI-Android/tree/master/storage

How do I preload multiple images using Glide for later use

I have many images that I want to preload and use later on. I want to make it so that I can load an image, hide it, and then load it again whenever I want.
https://github.com/bumptech/glide/wiki/Loading-and-Caching-on-Background-Threads#into
I have tried following this, but it doesn't work.
Here is my code:
private void loadImage() throws ExecutionException, InterruptedException {
FutureTarget<File> future = Glide.with(this)
.load(R.drawable.image1)
.downloadOnly(500, 500);
File cacheFile = future.get();
Bitmap myBitmap = Glide.with(this)
.load(cacheFile)
.asBitmap()
.centerCrop()
.into(500, 500)
.get();
Glide.with(this).load(myBitmap).into(image_name);
}
I tried using Picasso because I read that this can easily be done in it, but the images take really long to load in Picasso.

Updating ImageView based on URL

I have spent a lot of time trolling through multiple different threads concerning this topic, but I have yet to find an answer that works well with my code (Android SDK 23, in 2016). A lot of the answers are deprecated, and others just flat-out don't work like they're supposed to, and I was wondering if I could get a solid answer on this:
I am trying to include a Pokemon sprite (static image) in my program from Serebii. nums is a variable indicating the Pokemon's dex number (this one functions correctly, I promise). And this code is running in the main UI thread, which I know is frowned upon, but right now I'm trying to get the image loading, and then the smoothness of the app down. I don't really need a Bitmap, per se, but I need my ImageView to update and display the image given by the URL. How do I do it?
URL url = null;
try {
url = new URL("http://www.serebii.net/xy/pokemon/" + nums + ".png");
} catch (MalformedURLException e) {
e.printStackTrace();
}
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
mImageView.setImageBitmap(bmp);
Just use Picasso library, it will do all your image loading. You only need to provide the url of the image correctly.
String url = "http://www.serebii.net/xy/pokemon/" + nums + ".png";
Picasso.with(yourContext)
.load(url)
.into(mImageView);
You can use Picasso Library to load images.
a) Add Gradle into your project.
compile 'com.squareup.picasso:picasso:2.5.2'
b) Usage
Picasso.with(context).load("http://www.serebii.net/xy/pokemon/" + nums + ".png").into(imageView);
Also there are another libraries, you can use like
Fresco by Facebook, Universal Image loader
You can try using Picasso as:
Picasso.with(context)
.load(url)
.into(imageview);
Or use Universal Image loader as:
ImageLoader imageLoader = new ImageLoader(context);
imageLoader.displayImage(imageUri, imageView);
Use the Piassco library for it..Library link
For setting the Bitmap on the ImageView
Picasso.with(getContext()).load("your url").into(new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
//do what ever you want with your bitmap
imgView.setImageBitmap(loadedImage);///imgView is use to set the image in it
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
And another method of Picasso :-
Picasso.with(this)
.load("your_image_url")
.placeholder(R.drawable.no_image)
.error(android.R.drawable.stat_notify_error)
.networkPolicy(NetworkPolicy.OFFLINE)//user this for offline support
.into(YOUR_IMAEGVIEW);
OR
You can also use the Universal Image Loader..Here is the link Universal image loader
ImageLoader imageLoader = ImageLoader.getInstance(); // Get singleton instance
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(getActivity()));
imageLoader = com.nostra13.universalimageloader.core.ImageLoader.getInstance();
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.YOUR_DRAWABLE)
.showImageForEmptyUri(R.drawable.YOUR_DRAWABLE)
.showImageOnFail(R.drawable.YOUR_DRAWABLE)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.build();
imageLoader.displayImage("your_image_url", YOUR_IMAGEVIEW, null);

Categories

Resources