简体   繁体   中英

How to load URL into ImageView in a Android Wear Standalone App?

I'm working on a standalone Wear app. Everything works but the image loading is too slow.

The way I'm doing it is using Firebase Storage as a back-end. I'm getting the URL and using Glide loading it into an ImageView .

I also try using Picasso with the same result.

I tried to use the DaVinci library but its too old (3 years old). I followed this link: How to load URL image in android wear?

The code that I used is quite simple:

Picasso.get().load(imageUrl).into(iv);

and the Glide version:

Glide.with(iv.getContext()).load(imageUrl).into(iv);

The versions I'm using:

  • Gradle: 3.0.1
  • Google-services: 3.2.0/ 11.8.0 for the dependencies
  • Glide: 4.3.1
  • Picasso: 2.71828

This is the way I'm uploading the image to Firebase-Storage:

String filePath = photoFile.getAbsolutePath();
Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
mFormActivity.getContentResolver().notifyChange(photoURI, null);
int rotateImage = getCameraPhotoOrientation(filePath);

Matrix matrix = new Matrix();
matrix.postRotate(rotateImage);
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

FileOutputStream fos = null;
try {
    fos = new FileOutputStream(photoFile);
    rotatedBitmap.compress(Bitmap.CompressFormat.PNG, 25, fos);
    fos.close();
} catch (IOException e) {
    Log.d(TAG, "fixLandscapeOrientationCamera.error = " + e.toString());
    if (fos != null) {
        try {
            fos.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

I found the issue. Thanks Akshay Katariya for your time!!

I feel ashamed because it was a stupid mistake by my side. I was creating a bitmap and setting it into the ImageView before downloading the image. Anyway now its working perfectly so this is my code fully working for anyone that could try to achieve it.

I m using Picasso and Firebase Storage in a Standalone Wear App:

StorageReference imageReference = App.getStorage().getReference().child("images/" + mUser.getPicture());
imageReference.getDownloadUrl()
        .addOnSuccessListener(uri -> {
            Log.d("Testing", "loadSuggestionFace: setting the image");
            Picasso.get().load(uri.toString()).into(mFace1ProfilePicture);
        })
        .addOnFailureListener(exception -> Log.d(TAG, "getDownloadUrl.addOnFailureListener: error = " + exception.toString()));

App its the class extending Application where I'm initializing Firebase

mUser.getPicture() contains the filename(carlos.png for example)

mFace1ProfilePicture its the ImageView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM