目的:获取sd卡根目录下的文件夹
private String getImagesPath()
{
return createPathIfNotExist("/" + SD_APP_DIR_NAME + "/" + PHOTO_DIR_NAME);
}
private String createPathIfNotExist(String pPath)
{
boolean sdExist = android.os.Environment.MEDIA_MOUNTED.equals(android.os.Environment.getExternalStorageState());
if (!sdExist) {
Log.e("path", "SD卡不存在");
return null;
}
String _AbsolutePath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + pPath;
System.out.println("dbDir->" + _AbsolutePath);
File dirFile = new File(_AbsolutePath);
if (!dirFile.exists()) {
if (!dirFile.mkdirs())
{
Log.e("path", "文件夹创建失败");
return null;
}
}
return _AbsolutePath;
}
推荐一篇关于安卓路径的文章
彻底搞懂Android文件存储---内部存储,外部存储以及各种存储路径解惑