[Libgdx]How to automaticaly load assets?

I had no problem loading assets using this method


public static void loadAssets(String path)
    {
        File root = new File(path);
        File[] list = root.listFiles();
        if (list == null) return;

        for (File f : list)
        {
            if (f.isDirectory())
            {
                loadAssets(f.getAbsolutePath());
            } else
            {
                String fileType = f.getName().substring(f.getName().length()-4, f.getName().length());
                String fileToLoad = f.toString().split("assets")[1].substring(1);

                if(fileType.equalsIgnoreCase(".ogg"))
                {
                    Globals.assets.load(fileToLoad, Sound.class);
                    System.out.println("Loaded Sound : " + fileToLoad);
                }
                if(fileType.equalsIgnoreCase(".mp3"))
                {
                    Globals.assets.load(fileToLoad, Sound.class);
                    System.out.println("Loaded Music : " + fileToLoad);
                }
                if(fileType.equalsIgnoreCase(".png") || fileType.equalsIgnoreCase(".jpg"))
                {
                    Globals.assets.load(fileToLoad, Texture.class);
                    System.out.println("Loaded image : " + fileToLoad);
                }
            }
        }
    }

That I call like this

loadAssets(Gdx.files.getLocalStoragePath());

This works fine on desktop and load all assets that are in the “android/assets”. The problem is that “Gdx.files.getLocalStoragePath()” doesn’t seem to work as I wished on Android because I saw that the method loops only once instead of one per file.

So is there a way to run through all assets loaded in an Android?

FileHandle’s list method returns an array of FileHandles for the directory. It works on all platforms, but there is one exception: classpath type handles do not work with this as the files are treated a bit differently. You can view the last comment on this libgdx issue regarding what to do with the desktop implementation.