2017-05-09 106 views
1

我採取了兩種方法來使用滑動從Firebase存儲中獲取圖像。第一種方法工作正常,因爲在獲取downloadUrl之後,它使用滑動來加載圖像。無法使用Glide顯示來自Firebase存儲的圖片?

但第二個更方便,但它不適合我。

請幫我找出問題在這裏。

buidl.gradle:應用

dependencies { 
     // ..... not included glige dependency 
     compile 'com.firebaseui:firebase-ui-storage:0.6.0' 
    } 

第一種方法(工作):

// question.imgQuestion = "qimgs/-KiTpzP5t-xJOO5nSK0A/1493896460324-ch1pg2.jpg" 
final StorageReference ref = mStorage.getReference().child(question.imgQuestion); 

ref.getDownloadUrl().addOnSuccessListener(this, new OnSuccessListener<Uri>() { 
    @Override 
    public void onSuccess(Uri uri) { 
     Log.i(TAG, "Download URL : " + uri); // https://firebasestorage.googleapis.com/v0/b/questionpaper-ce229.appspot.com/o/qimgs%2F-KiTpzP5t-xJOO5nSK0A%2F1493896460324-ch1pg2.jpg?alt=media&token=ca2a3f6e-3eb5-4088-a48d-069ac8ad640b 
     Glide.with(QuizActivity.this) 
       .load(uri) 
       .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) 
       .into(mImageQuestion); 
    } 
}); 

第二種方法(不工作,但我想這一點)

// question.imgQuestion = "qimgs/-KiTpzP5t-xJOO5nSK0A/1493896460324-ch1pg2.jpg" 
final StorageReference ref = mStorage.getReference().child(question.imgQuestion); 
Glide.with(QuizActivity.this) 
    .using(new FirebaseImageLoader()) 
    .load(ref) 
    .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) 
    .into(mImageQuestion); 

注:此Firebase存儲實例是經過身份驗證的實例。

+1

代碼看起來沒問題。有沒有錯誤信息?考慮添加一個'RequestListener'來獲得更多的狀態。例如代碼請參閱此問題:http://stackoverflow.com/q/43853592/4815718。您也可以嘗試使用更新版本的FirebaseUI庫。最新的是1.2.0。 –

+0

謝謝,這是由於庫版本問題。使用的FirebaseUI版本:1.2.0和Firebase/Play服務版本:10.2.0。現在它正在工作。 –

回答

-1

更換.load(ref).load(ref.getDownloadUrl())

Glide.with(QuizActivity.this) 
.using(new FirebaseImageLoader()) 
.load(ref.getDownloadUrl()) 
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) 
.into(mImageQuestion); 
+0

語句'.load(ref.getDownloadUrl())'是編譯器不允許的。 –

+0

.load方法將在參數中採用firebase存儲對象。 –

0
StorageReference imagepath = storageReference.child("Images"); 
imagepath.putFile(selectedImage).addOnSuccessListener(new 
OnSuccessListener<UploadTask.TaskSnapshot>() { 
       @Override 
       public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 


       getimage = taskSnapshot.getDownloadUrl(); 

    Glide.with(QuizActivity.this) 
.using(new FirebaseImageLoader()) 
.load(getimage) 
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) 
.into(mImageQuestion); 
       } 
      }); 

試試這個,這個工作對我來說

0

我有這個問題太,原來的火力SDK的最新版本(10.2.4 )導致了這個問題,所以我回到了10.2.1,一切都很好。

相關問題