Image doesn't load from Firebase storage using Glide - java

I am trying to get an image from firebase storage in android studio but I am stuck and cannot understand the problem. The picture just doesnt load on the ImageView.
I followed the documentation that is on official site, but it didnt help, I also searched different question here but nothing helped me unfortunatly.
I have the user-permession for Internet in the manifest already
<uses-permission android:name="android.permission.INTERNET" />
This is the ImageView
<ImageView
android:id="#+id/picProfile"
android:layout_width="100dp"
android:layout_height="100dp"
....
/>
This is how the picture looks in storage
This is my code (Java)
StorageReference firebaseStorage=FirebaseStorage.getInstance().getReference("profile_pictures/2022_01_08_18_53_17.png");
Glide.with(getView().getContext())
.load(firebaseStorage)
.into(picProfile);
Also if I try to use this part of the code, the picture (sample_01)on the ImageView will be seen:
.placeholder(R.drawable.sample_01)
The question is what I should do for make the Glide show the picture from storage?
Thank you
UPDATE
I of course implemented the class
#GlideModule
public class MyAppGlideModule extends AppGlideModule {
#Override
public void registerComponents(Context context, Glide glide, Registry registry) {
// Register FirebaseImageLoader to handle StorageReference
registry.append(StorageReference.class, InputStream.class,
new FirebaseImageLoader.Factory());
}
}
and also in gradle the following
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
implementation 'com.firebaseui:firebase-ui-storage:3.3.0'

Related

Loading Image in Image View using Glide

I am working on an app which show an image which is loaded from my firebase database. I used Glide for that purpose.
I am using a button, on the click of that button a new activity will open which shows the image fetched from the url. The image load perfectly if url loaded correctly but if I cancelled in between, the app is crashing. Why it is happening and also, Is there any option to save the image in cache using glide, so that It can load it once and show without fetching it from firebase.
Here is my code to display image from url:
public void showImage(){
mStorageRef.child("TimeTable").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
url = uri.toString();
RequestOptions options = new RequestOptions().centerCrop().placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher_round);
Toast.makeText(TimeTable.this, uri.toString(),Toast.LENGTH_SHORT).show();
Glide.with(TimeTable.this).load(url).apply(options).into(image);
}
});
}
Here is the Error log, when I closed the activity before image loaded completely..
Please ask if any further details are required.
You can cache your images loading using Glide. I am referring to the tutorial here where you can learn the basics of image caching using Glide.
Now about the crashing problem, it clearly says that you are trying to load something from an activity which is already destroyed. As you have a firebase listener added where you are loading the image, you need to destroy the listener as you are leaving the activity.
You might consider using onPause, onDestroy functions to handle the remove listener action. Check the removeEventListener function of Firebase.
However, I would recommend using activity scoped versions of the loaders so that Firebase task takes care of these things by itself. Please see the answer here.

AdMob NativeExpressAds refuse to show up on actual Android device

I'm trying to display AdMob NativeExpressAds in my Android application.
Sample ads show up in the emulator and I thought everything seems fine.
However, on actual testing on real Android devices, ads refuse to show up - whether or not I set addTestDevice("...").
My code is:
public NativeExpressAdView getNativeExpressAdView(Activity activity) {
NativeExpressAdView adView = new NativeExpressAdView(activity);
adView.setAdListener(new TestAdListener(adView));
adView.setAdSize(new AdSize(adWidth, adHeight));
adView.setAdUnitId(adUnitID);
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
//adRequestBuilder.addTestDevice("187AE74C3A6B5BA1B5E94A46EC9FD3F6");
adView.loadAd(adRequestBuilder.build());
return adView;
}
Note: the adWidth and adHeight is exactly the same as what is set in the AdMob AdUnit.
and:
...
#Override
public void onAdLoaded() {
super.onAdLoaded();
Log.i("I/Ads", "onAdLoaded");
}
Yes, onAdLoaded is indeed called.
I also tried this, but it didn't work. I also research many other materials, but none worked.
EDIT:
I debugged further and found this error:
09-04 13:53:46.204 2502-2502/com.swars.android W/Ads: Not enough space to show ad. Needs 360x100 dp, but only has 320x0 dp.
The size is the same size as set in AdMob AdUnit. So, it seems that I should make is smaller. However, there is a mystery about the error because it says the height is 0 (320x0 dp). Can anyone help to shed some lights on this?
Config your RelativeLayer, so :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
android:paddingLeft="0dp"
android:paddingRight="0dp"
...
>
AdView config to:
<com.google.ads.AdView
android:id="#+id/adMobadView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
/>
Source

Fresco Library Not Loading Any Images

So due to memory issue I thought about using Facebook's Fresco library.
So this is what I did,
First I added the following dependencies,
compile 'com.facebook.fresco:fresco:1.3.0'
compile 'com.facebook.fresco:animated-gif:1.3.0'
Then I initialized it in application class,
Fresco.initialize(getApplicationContext());
Then I added SimpleDraweeView to layout file,
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/imageMessage"
android:layout_width="180dp"
android:layout_height="180dp"
/>
Then I added the code in my activity,
SimpleDraweeView gif = (SimpleDraweeView) row.findViewById(R.id.imageMessage);
ImageRequest request = ImageRequestBuilder.newBuilderWithSource (Uri.parse(url.get(position)))
.setProgressiveRenderingEnabled (true)
.build ();
DraweeController controller = Fresco.newDraweeControllerBuilder ()
.setImageRequest (request)
.setAutoPlayAnimations (true)
.build ();
gif.setController (controller);
But it's not loading images, I also tried different urls but same result, So what I'm missing...
i was facing same issue but not with gif. below is the code which load images, don't forget to initialize fresco.
Fresco.initialize(context);
SimpleDraweeView iv_image = (SimpleDraweeView)itemView.findViewById(R.id.iv_image);
iv_image.setImageURI(Uri.parse("your image url here"));
`
and here is xml
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/iv_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#drawable/iv_car"
fresco:viewAspectRatio="1.22"/>

detector.isOperational() always false on android

I'm using the new google plays service: Barcode detector, for this porposue I'm following this tutorial : https://search-codelabs.appspot.com/codelabs/bar-codes
But when I run the application on my real device(Asus Nexus 7), the text view of the app always is showing me "Couldn't set up the detector" and i don't know how to make it work >< ...
Here some code for fast debugging:
public class DecoderBar extends Activity implements View.OnClickListener{
private TextView txt;
private ImageView img;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_decoder);
Button b = (Button) findViewById(R.id.button);
txt = (TextView) findViewById(R.id.txtContent);
img = (ImageView) findViewById(R.id.imgview);
b.setOnClickListener(this);
}
// [...]
#Override
public void onClick(View v) {
Bitmap myBitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.popi);
img.setImageBitmap(myBitmap);
BarcodeDetector detector = new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
.build();
if(!detector.isOperational()){
// Always show this message, so, never is operational!
txt.setText("Could not set up the detector!");
return;
}
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Barcode> barcodes = detector.detect(frame);
Barcode thisCode = barcodes.valueAt(0);
txt.setText(thisCode.rawValue);
}
}
It looks like the first time barcode detector is used on each device, some download is done by Google Play Services. Here is the link:
https://developers.google.com/vision/multi-tracker-tutorial
And this is the excerpt:
The first time that an app using barcode and/or face APIs is installed
on a device, GMS will download a libraries to the device in order to
do barcode and face detection. Usually this is done by the installer
before the app is run for the first time.
I had this problem now. You can't update the Google Play Services. After I used the same as on the tutorial it works.
compile 'com.google.android.gms:play-services:7.8+'
Here is what was my case.
I was using BarcodeDetector for decoding QR codes from imported images. On 4 my testing devices it was working fine. On one was not reading anything from bitmap. I thought this might be incompatibility with android 5.0 but this was not the case. After hours of investigation I finally noticed that detector.isOperational(); returns false. The reason was:
The first time that an app using barcode and/or face APIs is installed on a device, GMS will download a libraries to the device in order to do barcode and face detection. Usually this is done by the installer before the app is run for the first time.
I had wi-fi off on that testing device. After turning it on and relaunching app, detector became operational and started decoding bitmaps.
To use the API, it's necessary to have internet connection, I had connection to my ADSL but not resolved DNS. Fixing that problem make my app works
Sometimes detector dependencies are downloaded when the app runs for the first time and not when the app installs. I too faced the same issue, the problem is either your network connection is weak or you don't have enough storage for download say 10% of the total space though it does not take that much space but downloads from Google Play Services does require good amount of storage and don't forget to clear cache(Simple check try to update any application from playstore). Refer this Github thread for more information.
Check your storage! make sure it is over 10%
That fixed my problem, and I answered it here too...
https://stackoverflow.com/a/43229272/6914806
you must not forget this:
add this to your AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="ocr"/>

Display Video thumbnails from URL

Okay this might be a stupid one but kindly pardon me because I'm new to Android. I'm working on an App in which I want to display video thumbnails using remote URL's like:
Video URL:
http://173.193.24.66/~kanz/video/flv/9.flv
.JPG URL:
http://173.193.24.66/~kanz/video/Images/9.jpg
I have got both the video URL's and Image File URL's that I want to display on thumbnails stored on SQL database. The only thing is I don't know how to put them in List view inside a ScrollView. I tried searching on the Internet but they all seem to give tutorials on how to display video thumbnails from sd card path. I want to use any of these URL's to display video thumbnails.
I heard about API's but I can't use Youtube API since Youtube is banned in my country. If anyone knows any useful API or any other hack around, let me know. It would be highly appreciated. I'm using Gingerbread.
Add these lines to your Module:app gradle:
dependencies {
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}
// pass video url into .load() method
Glide.with(context)
.asBitmap()
.load(/*Video Url*/)
.into(/*Name of Imageview*/);
Listview has its own scroll. So do not put listview inside a scroll view.
Use a custom listview to display the thumbnail.
Get your urls form the database.
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
http://www.youtube.com/watch?v=wDBM6wVEO70. The talk is about listview and performance.
Use a viewholder.http://developer.android.com/training/improving-layouts/smooth-scrolling.html.
If you are displaying lot of images in listview consider using one of the below libraries.
1.Universal Image loader. https://github.com/nostra13/Android-Universal-Image-Loader.
2.Lazy List. https://github.com/thest1/LazyList.
Both use caching.
For univarsal Image Loader
In your adapter constructor
File cacheDir = StorageUtils.getOwnCacheDirectory(a, "UniversalImageLoader/Cache");
imageLoader = ImageLoader.getInstance();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a)
// You can pass your own memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.enableLogging()
.build();
// Initialize ImageLoader with created configuration. Do it once.
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_id)//dummy image
.cacheInMemory()
.cacheOnDisc()
.displayer(new RoundedBitmapDisplayer(20))
.build();
In your getview()
ImageView image=(ImageView)vi.findViewById(R.id.imageview);
imageLoader.displayImage(imageurl, image,options);
Those tutorials are correct but you're missing a step. You need to download these images to the device first using the URL. Then you can set them up to be viewed in a listview.
See how to do this in these threads:
How to load an ImageView by URL in Android?
Android, Make an image at a URL equal to ImageView's image
There is a popular open source library that handles downloading and caching of images automatically. Check it out:
https://github.com/koush/UrlImageViewHelper

Categories

Resources