目的:獲取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", "文件夾創(chuàng)建失敗");
return null;
}
}
return _AbsolutePath;
}
推薦一篇關(guān)于安卓路徑的文章
徹底搞懂Android文件存儲(chǔ)---內(nèi)部存儲(chǔ)芬骄,外部存儲(chǔ)以及各種存儲(chǔ)路徑解惑