简体   繁体   English

.getDownloadUrl() 给我错误 - Android

[英].getDownloadUrl() gives me error - Android

I am trying to put data to firebase database but.getDownloadUrl() gives me error - Can not resolve method, Am i missing something?我正在尝试将数据放入 firebase 数据库但是.getDownloadUrl() 给我错误 - 无法解决方法,我错过了什么吗? I think i have to do it other way我想我必须以其他方式做

Android Studio 截图

Please help me by modifying this code and answering.请通过修改此代码并回答来帮助我。

Here is the code -这是代码 -

StorageReference file = FirebaseStorage.getInstance().getReference().child("message_images").child(messageId + ".jpg");

            file.putFile(url).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>()
            {
                @Override
                public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task)
                {
                    if(task.isSuccessful())
                    {
                        String imageUrl = task.getResult().getDownloadUrl().toString(); //here is the error

                        Map messageMap = new HashMap();
                        messageMap.put("message", imageUrl);
                        messageMap.put("type", "image");
                        messageMap.put("from", currentUserId);
                        messageMap.put("to", otherUserId);
                        messageMap.put("timestamp", ServerValue.TIMESTAMP);

                        HashMap<String, String> notificationData = new HashMap<>();
                        notificationData.put("from", currentUserId);
                        notificationData.put("type", "message");

                        Map userMap = new HashMap();
                        userMap.put("Messages/" + currentUserId + "/" + otherUserId + "/" + messageId, messageMap);
                        userMap.put("Messages/" + otherUserId + "/" + currentUserId + "/" + messageId, messageMap);

                        userMap.put("Chat/" + currentUserId + "/" + otherUserId + "/message", "You have sent a picture.");
                        userMap.put("Chat/" + currentUserId + "/" + otherUserId + "/timestamp", ServerValue.TIMESTAMP);
                        userMap.put("Chat/" + currentUserId + "/" + otherUserId + "/seen", ServerValue.TIMESTAMP);

                        userMap.put("Chat/" + otherUserId + "/" + currentUserId + "/message", "Has send you a picture.");
                        userMap.put("Chat/" + otherUserId + "/" + currentUserId + "/timestamp", ServerValue.TIMESTAMP);
                        userMap.put("Chat/" + otherUserId + "/" + currentUserId + "/seen", 0);

                        userMap.put("Notifications/" + otherUserId + "/" + notificationId, notificationData);

                        FirebaseDatabase.getInstance().getReference().updateChildren(userMap, new DatabaseReference.CompletionListener()
                        {
                            @Override
                            public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference)
                            {
                                sendButton.setEnabled(true);

                                if(databaseError != null)
                                {
                                    Log.d(TAG, "sendMessage(): updateChildren failed: " + databaseError.getMessage());
                                }
                            }
                        });
                    }
                }
            });

You should add getStorage()您应该添加getStorage()

String imageUrl = task.getResult().getStorage().getDownloadUrl().toString();

correct code is: task.getResult().getMetadata().getReference().getDownloadUrl();正确的代码是: task.getResult().getMetadata().getReference().getDownloadUrl();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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