Android 将文件从本地存储上载到firebase

Android 将文件从本地存储上载到firebase,android,firebase-storage,Android,Firebase Storage,我正在制作一个聊天应用程序,我们可以上传我们的文件到firebase,就像我们在中选择照片采集器一样,如果我们选择了一个图像,点击它后,就会被选中,并发送和聊天照片,就像whatsapp一样。照片采集器工作正常,但当我选择图像时,它无法发送图像,因此无法上载 触发光电选择器的代码意图: mPhotoPickerButton.setOnClickListener(new View.OnClickListener() { @Override

我正在制作一个聊天应用程序,我们可以上传我们的文件到firebase,就像我们在中选择照片采集器一样,如果我们选择了一个图像,点击它后,就会被选中,并发送和聊天照片,就像whatsapp一样。照片采集器工作正常,但当我选择图像时,它无法发送图像,因此无法上载

触发光电选择器的代码意图:

       mPhotoPickerButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    // TODO: Fire an intent to show an image picker
                    Log.d(TAG, "onClick: is it working?");
                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType("image/*");
                    intent.putExtra(Intent.EXTRA_LOCAL_ONLY,true);
                    startActivityForResult(Intent.createChooser(intent,"Complete action using"),RC_PHOTO_PICKER);
                }
            });
提取要上传的照片的代码为:

else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){
                   Uri selectedImageUri = data.getData();
                   StorageReference photoRef = mStorageReference.child(selectedImageUri.getLastPathSegment());

                   //upload file to firebase storage
                   photoRef.putFile(selectedImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                       @Override
                       public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                           Uri downloadUrl =   taskSnapshot.getDownloadUrl();
                           FriendlyMessage friendlyMessage = new FriendlyMessage(null,mUsername,downloadUrl.toString());
                           mMessageDatabaseReference.push().setValue(friendlyMessage);
                       }
                   });
日志:

.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
04-21 11:56:08.401 9124-9401/com.google.firebase.udacity.friendlychat I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6
04-21 11:56:08.401 9124-9401/com.google.firebase.udacity.friendlychat I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 6
04-21 11:56:08.410 9124-9327/com.google.firebase.udacity.friendlychat I/FA: Tag Manager is not found and thus will not be used
04-21 11:56:08.440 9124-9404/com.google.firebase.udacity.friendlychat D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
04-21 11:56:08.446 9124-9401/com.google.firebase.udacity.friendlychat W/System: ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/0000002d/n/armeabi-v7a
04-21 11:56:08.447 9124-9401/com.google.firebase.udacity.friendlychat W/System: ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/0000002d/n/armeabi
04-21 11:56:08.466 9124-9124/com.google.firebase.udacity.friendlychat D/FirebaseApp: Notifying auth state listeners.
04-21 11:56:08.466 9124-9124/com.google.firebase.udacity.friendlychat D/FirebaseApp: Notified 0 auth state listeners.
04-21 11:56:08.519 9124-9404/com.google.firebase.udacity.friendlychat I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build:  (Ifd751822f5)
                                                                                    OpenGL ES Shader Compiler Version: XE031.06.00.05
                                                                                    Build Date: 01/26/16 Tue
                                                                                    Local Branch: AU12_SBA
                                                                                    Remote Branch: 
                                                                                    Local Patches: 
                                                                                    Reconstruct Branch: 
04-21 11:56:08.521 9124-9404/com.google.firebase.udacity.friendlychat I/OpenGLRenderer: Initialized EGL, version 1.4
04-21 11:56:08.887 9124-9124/com.google.firebase.udacity.friendlychat W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
04-21 11:56:09.110 9124-9404/com.google.firebase.udacity.friendlychat V/RenderScript: 0xb7aa3c00 Launching thread(s), CPUs 4

是的,我发现了问题

公开FriendlyMessageModel类的所有成员

public class FriendlyMessage {

    public String text;
    public String name;
    public String photoUrl;

    public FriendlyMessage() {
    }

    public FriendlyMessage(String text, String name, String photoUrl) {
        this.text = text;
        this.name = name;
        this.photoUrl = photoUrl;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhotoUrl() {
        return photoUrl;
    }

    public void setPhotoUrl(String photoUrl) {
        this.photoUrl = photoUrl;
    }
}

要选择多个图像吗?出了什么问题?错误?例外情况?logcat?@kdblue不我不想选择多个images@greenapps运行时没有明显的错误,但是类加载器引用了未知路径:/data/data/com.google.android.gms/app_chimera/m/000000 2d/n/armeabi-v7a“@Vishal那么您的第一个代码片段就对了!在logcat警告中:1)找不到应用程序信息。能否在引用的位置显示mStorageReference?在onCreate:mStorageReference=mFirebaseStorage.getReference().child(“聊天室照片”);//我在firebase中为存储创建了聊天室照片,这是我在上面添加的else if代码中的另一次创建。是否要查看我的整个MainActivity类?
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}
public class FriendlyMessage {

    public String text;
    public String name;
    public String photoUrl;

    public FriendlyMessage() {
    }

    public FriendlyMessage(String text, String name, String photoUrl) {
        this.text = text;
        this.name = name;
        this.photoUrl = photoUrl;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhotoUrl() {
        return photoUrl;
    }

    public void setPhotoUrl(String photoUrl) {
        this.photoUrl = photoUrl;
    }
}