wxr
2022-11-24 2af932533ef851bf983385244e9912976dbd4daa
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.mm.android.deviceaddmodule.utils;
 
import android.content.Context;
import android.os.Build;
import android.os.Environment;
 
import com.mm.android.deviceaddmodule.mobilecommon.utils.LogUtil;
 
import java.io.File;
import java.security.NoSuchAlgorithmException;
 
 
public class SDsolutionUtility {
 
    private static String mUsername;
    private static String md5name;
    private static String[] dirFolder = {"snapshot","video","mp4","thumb","facedetection","cache", "temp"};
    private static String ALBUM_PATH=Environment.getExternalStorageDirectory()+File.separator;
 
 
    private static Context mContext;
 
 
    public static void initContext(Context context) {
        mContext = context;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            ALBUM_PATH = mContext.getExternalFilesDir("demo").getAbsolutePath();
            LogUtil.debugLog("rrrrr","ALBUM_PATH::"+ALBUM_PATH);
        }
    }
 
    public static void createDir(String username)
    {
        mUsername = username.toLowerCase();
        try {
            //由于服务器不区分大小写,先统一将所有名字转成小写,再转MD5
            md5name = MD5Utility.getMD5(username.toLowerCase());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        String userPath = ALBUM_PATH + md5name;
        String newUserPath = ALBUM_PATH;
        File dirUserFile = new File(userPath);
        File newDirUserFile = new File(newUserPath);
        if (dirUserFile.exists()) {
            FileHelper.renameFile(dirUserFile, newDirUserFile);
        }
 
 
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            for (int i = 0; i < dirFolder.length; i++) {
                String path = ALBUM_PATH+File.separator +dirFolder[i]+File.separator;
                LogUtil.debugLog("rrrrr","path::"+path);
                File dirEasy4ipFile = new File(path);
                if (!dirEasy4ipFile.exists()) {
                    dirEasy4ipFile.mkdirs();
                }
            }
 
        } else {
            boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
            if (!sdCardExist) {
                //
            } else {
                for (int i = 0; i < dirFolder.length; i++) {
                    String path = ALBUM_PATH + File.separator + dirFolder[i] + File.separator;
                    File dirEasy4ipFile = new File(path);
                    if (!dirEasy4ipFile.exists()) {
                        dirEasy4ipFile.mkdirs();
                    }
                }
            }
        }
    }
 
 
 
    public static String getCachePath()
    {
        return ALBUM_PATH+dirFolder[5]+File.separator;
    }
 
    public static String getTempPath(){
        return ALBUM_PATH+dirFolder[6]+File.separator;
    }
    
}