admin
6 天以前 7f0825f8195a522ed7e8bcdb6347f3a719e06c74
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.weikou.beibeivideo.util;
 
import java.lang.reflect.Method;
 
import android.app.Activity;
import android.content.Context;
import android.os.storage.StorageManager;
 
public class StorageList {
    private Context context;
    private StorageManager mStorageManager;
    private Method mMethodGetPaths;
 
    public StorageList(Context context) {
        this.context = context;
        if (context != null) {
            mStorageManager = (StorageManager) context
                    .getSystemService(Activity.STORAGE_SERVICE);
            try {
                mMethodGetPaths = mStorageManager.getClass().getMethod(
                        "getVolumePaths");
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
        }
    }
 
    public String[] getVolumePaths() {
        String[] paths = null;
        try {
 
            paths = (String[]) mMethodGetPaths.invoke(mStorageManager);
 
        } catch (Exception e) {
            e.printStackTrace();
        }
        // catch (IllegalAccessException e) {
        // e.printStackTrace();
        // } catch (InvocationTargetException e) {
        // e.printStackTrace();
        // } catch (Exception e) {
        // e.printStackTrace();
        // }
        return paths;
    }
}