我想在我的聊天应用程序中的图像视图夹中显示个人资料图片。我已经实现了Firebase auth sign in方法,如谷歌和Facebook。所以我想在用户聊天时显示他们的图片。我可以通过
FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl();
显示当前用户的图片。但是,当我想获得另一个用户的图像时?所以我尝试了以下方法。
当他们注册到应用程序时,我可以获得他们的个人资料图片,并将其上传到Firebase存储。之后,我可以在应用程序的聊天头中使用它。所以下面的代码是
Uri dpUri = currentFirebaseUser.getPhotoUrl();
if (dpUri != null) {
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Uploading...");
progressDialog.show();
final StorageReference ref = storageReference.child(currentFirebaseUser.getUid());
ref.putFile(dpUri)
.addOnSuccessListener(taskSnapshot -> {
ref.getDownloadUrl().addOnSuccessListener(uri -> databaseReference.child("Users").child(currentFirebaseUser.getUid()).child("URL").setValue(uri.toString()));
progressDialog.dismiss();
LocationOn();
.addOnFailureListener(e -> {
progressDialog.dismiss();
Toast.makeText(SignActivity.this, "Failed " + e.getMessage(), Toast.LENGTH_SHORT).show();
.addOnProgressListener(taskSnapshot -> {
double progress = (100.0 * taskSnapshot.getBytesTransferred() / taskSnapshot
.getTotalByteCount());
progressDialog.setMessage("Uploaded " + (int) progress + "%");
但是无法阅读,我得到了这个错误。
E/UploadTask: could not locate file for uploading:https://lh3.googleusercontent.com/a/AATXAJzFGstrkeyXMQUU9XIKEXIL8jgEgm1T-EKi3AW1=s96-c
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
E/StorageException: No content provider: https://lh3.googleusercontent.com/a/AATXAJzFGstrkeyXMQUU9XIKEXIL8jgEgm1T-EKi3AW1=s96-c
java.io.FileNotFoundException: No content provider: https://lh3.googleusercontent.com/a/AATXAJzFGstrkeyXMQUU9XIKEXIL8jgEgm1T-EKi3AW1=s96-c
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1979)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1808)
at android.content.ContentResolver.openInputStream(ContentResolver.java:1485)
at com.google.firebase.storage.UploadTask.<init>(UploadTask.java:131)
at com.google.firebase.storage.StorageReference.putFile(StorageReference.java:240)
at com.myapp.SignActivity.uploadImage(SignActivity.java:143)
at com.axresapps.wheresapplk.SignActivity.lambda$onCreate$2$SignActivity(SignActivity.java:123)
at com.myapp.-$$Lambda$SignActivity$__O5f7J8hhcqZRFrdV0j4-3CaQk.onClick(Unknown Source:4)
at android.view.View.performClick(View.java:8160)
at android.widget.TextView.performClick(TextView.java:16222)
at android.view.View.performClickInternal(View.java:8137)
at android.view.View.access$3700(View.java:888)
at android.view.View$PerformClick.run(View.java:30236)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8512)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
E/StorageException: No content provider: https://lh3.googleusercontent.com/a/AATXAJzFGstrkeyXMQUU9XIKEXIL8jgEgm1T-EKi3AW1=s96-c
java.io.FileNotFoundException: No content provider: https://lh3.googleusercontent.com/a/AATXAJzFGstrkeyXMQUU9XIKEXIL8jgEgm1T-EKi3AW1=s96-c
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1979)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1808)
at android.content.ContentResolver.openInputStream(ContentResolver.java:1485)
at com.google.firebase.storage.UploadTask.<init>(UploadTask.java:131)
at com.google.firebase.storage.StorageReference.putFile(StorageReference.java:240)
at com.axresapps.wheresapplk.SignActivity.uploadImage(SignActivity.java:143)
at com.myapp.SignActivity.lambda$onCreate$2$SignActivity(SignActivity.java:123)
at com.axresapps.wheresapplk.-$$Lambda$SignActivity$__O5f7J8hhcqZRFrdV0j4-3CaQk.onClick(Unknown Source:4)
at android.view.View.performClick(View.java:8160)
at android.widget.TextView.performClick(TextView.java:16222)
at android.view.View.performClickInternal(View.java:8137)
at android.view.View.access$3700(View.java:888)
at android.view.View$PerformClick.run(View.java:30236)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8512)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
E/StorageException: No content provider: https://lh3.googleusercontent.com/a/AATXAJzFGstrkeyXMQUU9XIKEXIL8jgEgm1T-EKi3AW1=s96-c
java.io.FileNotFoundException: No content provider: https://lh3.googleusercontent.com/a/AATXAJzFGstrkeyXMQUU9XIKEXIL8jgEgm1T-EKi3AW1=s96-c
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1979)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1808)
at android.content.ContentResolver.openInputStream(ContentResolver.java:1485)
at com.google.firebase.storage.UploadTask.<init>(UploadTask.java:131)
at com.google.firebase.storage.StorageReference.putFile(StorageReference.java:240)
at com.axresapps.wheresapplk.SignActivity.uploadImage(SignActivity.java:143)
at com.axresapps.wheresapplk.SignActivity.lambda$onCreate$2$SignActivity(SignActivity.java:123)
at com.axresapps.wheresapplk.-$$Lambda$SignActivity$__O5f7J8hhcqZRFrdV0j4-3CaQk.onClick(Unknown Source:4)
at android.view.View.performClick(View.java:8160)
at android.widget.TextView.performClick(TextView.java:16222)
at android.view.View.performClickInternal(View.java:8137)
at android.view.View.access$3700(View.java:888)
at android.view.View$PerformClick.run(View.java:30236)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8512)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
请帮助我解决这个问题或建议我用其他方法来完成我的任务。