Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么赢了';图像Url是否保存在Firebase实时数据库中?_Android_Firebase_Firebase Realtime Database_Firebase Storage - Fatal编程技术网

Android 为什么赢了';图像Url是否保存在Firebase实时数据库中?

Android 为什么赢了';图像Url是否保存在Firebase实时数据库中?,android,firebase,firebase-realtime-database,firebase-storage,Android,Firebase,Firebase Realtime Database,Firebase Storage,伙计们,我正在为我的一个模块做这个项目,而且我对android开发还相当陌生。下面的代码运行良好,在Logcat中,URL仍然显示它无法保存到实时数据库。有人能帮我吗 @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if

伙计们,我正在为我的一个模块做这个项目,而且我对android开发还相当陌生。下面的代码运行良好,在Logcat中,URL仍然显示它无法保存到实时数据库。有人能帮我吗

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PICTURE_RESULT && resultCode == RESULT_OK) {

        Uri imageUrl = data.getData();
        StorageReference ref = FirebaseUtil.mStorageRef.child(imageUrl.getLastPathSegment());
        ref.putFile(imageUrl).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                if (taskSnapshot.getMetadata() != null) {
                    if (taskSnapshot.getMetadata().getReference() != null) {
                        Task<Uri> result = taskSnapshot.getStorage().getDownloadUrl();
                        result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                            @Override
                            public void onSuccess(Uri uri) {
                                String imageUrl = uri.toString();
                                String pictureName = taskSnapshot.getStorage().getPath();
                                prod.setImageUrl(imageUrl);
                                prod.setImageName(pictureName);
                                Log.d("Image URL", prod.getImageUrl());
                                Log.d("URL Name", pictureName);

                            }
                        });
                    }
                }
            }
        });
    }
}
@覆盖
受保护的void onActivityResult(int-requestCode、int-resultCode、@Nullable-Intent-data){
super.onActivityResult(请求代码、结果代码、数据);
if(requestCode==PICTURE\u RESULT&&resultCode==RESULT\u OK){
Uri imageUrl=data.getData();
StorageReference ref=FirebaseUtil.mStorageRef.child(imageUrl.getLastPathSegment());
ref.putFile(imageUrl).addOnSuccessListener(新的OnSuccessListener(){
@凌驾
成功时公共无效(UploadTask.TaskSnapshot TaskSnapshot){
如果(taskSnapshot.getMetadata()!=null){
如果(taskSnapshot.getMetadata().getReference()!=null){
任务结果=taskSnapshot.getStorage().getDownloadUrl();
result.addOnSuccessListener(新的OnSuccessListener(){
@凌驾
成功时的公共无效(Uri){
字符串imageUrl=uri.toString();
字符串pictureName=taskSnapshot.getStorage().getPath();
prod.setImageUrl(imageUrl);
prod.setImageName(pictureName);
Log.d(“图像URL”,prod.getImageUrl());
Log.d(“URL名称”,pictureName);
}
});
}
}
}
});
}
}
Logcat

2021-05-01 16:24:32.185 3446-3446/com.mad.ui_连接D/图像URL:


2021-05-01 16:24:32.185 3446-3446/com.mad.ui_connection D/URL Name:/item_pictures/image:27376据我所知,您共享的代码没有将URL保存到数据库中。您忘了包含该代码了吗?private void saveItem(){prod.setTitle(txtTitle.getText().toString());prod.setDescription(txtDescription.getText().toString());prod.setPrice(txtPrice.getText().toString());///ProductActivity prod=new ProductActivity(title,description,price,“);//如果(prod.getId()==null){mDatabaseReference.push().setValue(prod);}或者{mDatabaseReference.child(prod.getId()).setValue(prod);}这就是我将数据发送到firebase数据库的地方。是的,这就是问题所在。映像正在存储中,但未保存在database@chathurangajayadithya请编辑您的问题,并在问题中添加相应的代码,而不是作为注释。请回复@。