import android.content.Context;
import android.os.Environment;
import android.util.Log;
import java.io.File;
/**
- @author benny
- @date 2020/9/10 9:17
- @功能: 存储目录获取 Android应用的清除数据和清除缓存、数据保存路径 SD卡
*/
public class FileManager {
private static String TAG = FileManager.class.getSimpleName();
/**
* 获取存储路径
*/
public static String getAbsolutePath(Context context) {
return getStorageFile(context).getAbsolutePath();
}
/**
* 获取存储目录
*/
public static File getStorageFile(Context context) {
return getExternalStorageDirectory(context);
}
/**
* @author benny
* @create 2020/9/10 9:32
* @Describe sd卡的路径
*/
public static File getExternalStorageDirectory(Context context) {
File file = Environment.getExternalStorageDirectory();
Log.i(TAG, "getExternalStorageDirectory: " + file.getAbsolutePath());
return file;
}
/**
* @return 正常加载的状态值
* @author benny
* @create 2020/9/10 9:27
* @Describe SD卡加载状态
*/
public static String getExternalStorageState(Context context) {
String file = Environment.getExternalStorageState();
Log.i(TAG, "getExternalStorageState: " + file);
return file;
}
/**
* @return /storage/emulated/0/Android/data/packageName/cache
* @author benny
* @create 2020/9/10 9:30
* @Describe 有SD卡的情况:应用的缓存目录
*/
public static File getExternalCacheDir(Context context) {
File file = context.getExternalCacheDir();
assert file != null;
Log.i(TAG, "getExternalCacheDir: " + file.getAbsolutePath());
return file;
}
/**
* @return /data/data/packageName/cache
* @author benny
* @create 2020/9/10 9:30
* @Describe 无SD卡的情况:应用的缓存目录
*/
public static File getCacheDir(Context context) {
File file = context.getCacheDir();
Log.i(TAG, "getCacheDir: " + file.getAbsolutePath());
return file;
}
/**
* @return /storage/emulated/0/Android/data/packageName/files/test
* @author benny
* @create 2020/9/10 9:30
* @Describe 有SD卡的情况:应用的存储目录
*/
public static File getExternalFilesDir(Context context) {
File file = context.getExternalFilesDir(context.getPackageName());
assert file != null;
Log.i(TAG, "getExternalFilesDir: " + file.getAbsolutePath());
return file;
}
/**
* @return /data/data/packageName/files
* @author benny
* @create 2020/9/10 9:30
* @Describe 无SD卡的情况:应用的存储目录
*/
public static File getFilesDir(Context context) {
File file = context.getFilesDir();
Log.i(TAG, "getFilesDir: " + file.getAbsolutePath());
return file;
}
}