Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;

import android.os.storage.StorageManager;

public class Main {

    public static List<String> getDirs(Context context) {
        List<String> dirs = new ArrayList<String>();
        StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
        try {
            Class[] paramClasses = {};
            Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", paramClasses);
            getVolumePathsMethod.setAccessible(true);
            Object[] params = {};
            Object invoke = getVolumePathsMethod.invoke(storageManager, params);
            for (int i = 0; i < ((String[]) invoke).length; i++) {
                // System.out.println(((String[])invoke)[i]);
                dirs.add(((String[]) invoke)[i]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dirs;
    }
}