Android/Java:显示资产 and/or internal/sd 存储中的图像

Android/Java: displaying images from assets and/or internal/sd storage

我正在开发一个 android 应用程序,我想在其中显示 ImageView 中的图像。此时(开发期间),我已将图像存储在 'assets' 文件夹中。

使用 assets 的主要原因是因为 getAssets().list() 命令,所以我最终得到一个包含文件夹内容的数组(我需要知道文件夹中有多少文件以及什么他们的文件名是)

public boolean listAssetFiles(String path) {
    try {
        fileList = getAssets().list(path);
        numberOfFiles = fileList.length;
    } catch (IOException e) {
        return false;
    }
    return true;
}

但是,我希望用户将自己的图像导入应用程序,同时 运行 应用程序从内部 and/or sd 存储。

我怀疑,经过一些谷歌搜索,是否可以将这些图像导入资产文件夹,但我不确定。

因此我有两个问题:

1) 是否可以在 运行 应用程序/或启动时将图像导入资产文件夹?

2) 如果没有,我如何在内部 and/or sd 存储中创建一个特定文件夹的文件名数组。

任何人都可以在正确的方向上推动我吗?

is it possible to import images, whilst running the application / or at startup, into the assets folder?

没有。资产和资源在运​​行时是只读的。

how can I create an array of the filenames of a particular folder in the internal and/or sd storage.

首先,准确了解 internal storage, external storage, and removable storage 是什么。

然后,获取一个 File 对象,指向您要从中获取文件的位置。然后,对该 File 对象调用 listFiles()

如果要允许用户选择目录,请考虑使用 file/directory picker library