我正在开发一个 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;
}
但是,我希望用户在从内部和/或 SD 存储运行应用程序时将自己的图像导入应用程序。
我怀疑,经过一些谷歌搜索,是否可以将这些图像导入 Assets 文件夹,但我不确定。
因此我有两个问题:
1) 是否可以在运行应用程序时/或在启动时将图像导入 Assets 文件夹?
2) 如果没有,我如何在内部和/或 sd 存储中创建一个特定文件夹的文件名数组。
任何人都可以在正确的方向上插入我吗?
最佳答案
is it possible to import images, whilst running the application / or at startup, into the assets folder?
没有。 Assets 和资源在运行时是只读的。
how can I create an array of the filenames of a particular folder in the internal and/or sd storage.
首先,了解到底是什么internal storage , external storage , 和 removable storage是。
然后,获取一个File
对象,指向您希望从中获取文件的位置。然后,对该 File
对象调用 listFiles()
。
如果要允许用户选择目录,请考虑使用 file/directory picker library .
关于java - 安卓/Java : displaying images from assets and/or internal/sd storage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44874242/