Android-从文件夹加载所有文件

Android-从文件夹加载所有文件,android,file,resources,directory,loading,Android,File,Resources,Directory,Loading,在我的特殊情况下,我正在编写一个fartbutton应用程序。 但我想知道如何做到这一点-特别是对于另一个更严肃的应用程序 我的问题是res/raw目录中有三种不同的放屁声音。 现在,我手动单独加载它们,如下所示: // soundPool is the class's attribute. // Initialize SoundPool with all sounds: setVolumeControlStream(AudioManager.STREAM_MUSIC); soundPool =

在我的特殊情况下,我正在编写一个fartbutton应用程序。
但我想知道如何做到这一点-特别是对于另一个更严肃的应用程序

我的问题是res/raw目录中有三种不同的放屁声音。
现在,我手动单独加载它们,如下所示:

// soundPool is the class's attribute.
// Initialize SoundPool with all sounds:
setVolumeControlStream(AudioManager.STREAM_MUSIC);
soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);

soundCollection[0] = soundPool.load(this, R.raw.fart1, 0);
soundCollection[1] = soundPool.load(this, R.raw.fart2, 0);
soundCollection[2] = soundPool.load(this, R.raw.fart3, 0);
我希望能够简单地加载(任何)特定文件夹中的所有文件。
这样我就可以轻松地添加更多声音,而不必手动导入它们

对于fartbutton应用程序,这不是一个真正的问题。
但对于一种词汇应用程序来说,能够将新词添加到该文件夹并动态导入是一项关键功能。

我在搜索时发现的许多建议都没有详细说明,使我无法遵循它们。
大多数时候,他们也在从SD卡加载文件


如果你能给我解释一下(尽可能广泛地)这方面的方法,我将非常感谢你的时间

我们开始吧,删除我的旧答案,这应该是一个更直接的解决方案:

将子文件夹放在资产目录中,下面的内容应该迭代并打开每个资产

    String[] file_arr = null;
    Context m_context = getActivity();

    try {
        file_arr = m_context.getAssets().list(subfolderName);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    InputStream is;

    for(String filename : file_arr){
        try {
            is = m_context.getAssets().open(filename);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        //..do something

    }

我怎么能给你发个私人信息,阿图·德图D我非常感谢你纠正了我的德语拼写!;)这正是我想要的!非常感谢@命名空间,您是如何编写子文件夹名的?我试图在我的SD卡中输入一个子文件夹的名称,但它无法识别它(只是一个名称),因此我在该部分得到一个空指针错误。