setup Root Path in StorageManager - Android android.os.storage

Android examples for android.os.storage:StorageManager

Description

setup Root Path in StorageManager

Demo Code


//package com.java2s;

import java.io.File;

import android.content.Context;
import android.os.Environment;
import android.os.storage.StorageManager;

public class Main {
    public static String sRootPath;
    private static String sLogPath;

    public static void setupRootPath(Context context) {
        StorageManager sm = (StorageManager) context
                .getSystemService(Context.STORAGE_SERVICE);
        String systemPath = null;
        try {//from   w ww .ja  v  a  2 s.c o  m
            String[] paths = (String[]) sm.getClass()
                    .getMethod("getVolumePaths", null).invoke(sm, null);
            for (int i = 0; i < paths.length; i++) {
                String status = (String) sm.getClass()
                        .getMethod("getVolumeState", String.class)
                        .invoke(sm, paths[i]);
                if (status.equals(android.os.Environment.MEDIA_MOUNTED)) {
                    systemPath = paths[i];
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            systemPath = Environment.getExternalStorageDirectory()
                    .getPath();
        }

        sRootPath = systemPath + File.separator + "AlienPlayer"
                + File.separator;
        sLogPath = sRootPath + "Log" + File.separator;
    }
}

Related Tutorials