Monday, October 29, 2018

Android 외장 SD카드 메모리 경로 획득

public static String getExternalSdCardPath() {
    File root = Environment.getExternalStorageDirectory();
    if (root == null)
        return null;

    File parent = root.getParentFile();
    if (parent == null)
        return null;

    File storage = parent.getParentFile();
    if (storage == null)
        return null;

    File[] files = storage.listFiles();
    for (File file : files) {
        String path = file.getName();
        if (path.equals("emulated"))
            continue;
        if (path.equals("self"))
            continue;
        return file.getAbsolutePath();
    }
    return null;
}


No comments:

Post a Comment