Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;

import java.io.IOException;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**
     * @param filePath filePath example("pictures")
     */
    public static List<String> traversalAssetsFiles(Context context, String filePath) {
        List<String> files = new ArrayList<>();
        try {
            for (String file : context.getAssets().list(filePath)) {
                if (file != null && !file.isEmpty()) {
                    if (file.endsWith(".jpg") || file.endsWith(".gif") || file.endsWith(".png")) {
                        files.add(file);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return files;
    }
}