Android / Java:显示资产和/或内部/ sd存储中的图像

时间:2022-12-12 00:27:56

I am working on an android app in which I want to display images in ImageView. At this point (during development), I have stored the images in the 'assets' folder.

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

The main reason for using assets is because of the getAssets().list() command, such that I end up with an array with the contents of the folder (I need to know how many files are in the folder and what their filenames are)

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

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

However, I want users to import their own images into the application whilst running the application from internal and/or sd storage.

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

I doubt, after some googling, whether it is possible to import these images to the assets folder, but I am not sure.

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

I therefore have two questions:

因此,我有两个问题:

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

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

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

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

anyone who can give me a push in the right direction?

谁能给我一个正确的方向?

1 个解决方案

#1


2  

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

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

No. Assets and resources are read-only at runtime.

不可以。资产和资源在运​​行时是只读的。

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

如何在内部和/或sd存储中创建特定文件夹的文件名数组。

First, learn exactly what internal storage, external storage, and removable storage are.

首先,准确了解内部存储,外部存储和可移动存储。

Then, get a File object pointing to where you want the files from. Then, call listFiles() on that File object.

然后,获取指向文件所在位置的File对象。然后,在该File对象上调用listFiles()。

If you want to allow the user to choose the directory, consider using a file/directory picker library.

如果要允许用户选择目录,请考虑使用文件/目录选取器库。

#1


2  

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

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

No. Assets and resources are read-only at runtime.

不可以。资产和资源在运​​行时是只读的。

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

如何在内部和/或sd存储中创建特定文件夹的文件名数组。

First, learn exactly what internal storage, external storage, and removable storage are.

首先,准确了解内部存储,外部存储和可移动存储。

Then, get a File object pointing to where you want the files from. Then, call listFiles() on that File object.

然后,获取指向文件所在位置的File对象。然后,在该File对象上调用listFiles()。

If you want to allow the user to choose the directory, consider using a file/directory picker library.

如果要允许用户选择目录,请考虑使用文件/目录选取器库。