我知道文档显示了如何列出这样的项目:
listRef.listAll()
.addOnSuccessListener(new OnSuccessListener<ListResult>() {
@Override
public void onSuccess(ListResult listResult) {
for (StorageReference prefix : listResult.getPrefixes()) {
// All the prefixes under listRef.
// You may call listAll() recursively on them.
}
for (StorageReference item : listResult.getItems()) {
// All the items under listRef.
}
}
})
...但是如何从item
中获取数据?例如,图像uri或元数据。
public class Wallpaper {
private String wallpaperName;
private Uri imageUri;
public Wallpaper(String wallpaperName,Uri imageUri) {
this.wallpaperName = wallpaperName;
this.imageUri = imageUri;
}
public Wallpaper() {
}
public String getWallpaperName() {
return wallpaperName;
}
public void setWallpaperName(String wallpaperName) {
this.wallpaperName = wallpaperName;
}
public Uri getImageUri() {
return imageUri;
}
public void setImageUri(Uri imageUri) {
this.imageUri = imageUri;
}
}
public class ShowWallpapers extends AppCompatactivity {
private RecyclerView recyclerView;
private RecyclerViewAdapter recyclerViewAdapter;
private List<Wallpaper> wallpaperList;
private StorageReference storageReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_wallpapers);
storageReference = FirebaseStorage.getInstance().getReference("wallpapers");
recyclerView = findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
wallpaperList = new ArrayList<>();
storageReference.listAll()
.addOnSuccessListener(new OnSuccessListener<ListResult>() {
@Override
public void onSuccess(ListResult listResult) {
for (StorageReference item : listResult.getItems()) {
// i want to set-up my Wallpaper object here and add it to my list
// but how can i do that
}
recyclerViewAdapter = new RecyclerViewAdapter(ShowWallpapers.this,wallpaperList);
recyclerView.setadapter(recyclerViewAdapter);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
}
我的存储的控制台视图:https://i.imgur.com/jnjW6Ko.png