Skip to content

Instantly share code, notes, and snippets.

@juliancadi
Last active October 10, 2019 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliancadi/31dd81d8600e9d405ccb6ca4f3c6adcd to your computer and use it in GitHub Desktop.
Save juliancadi/31dd81d8600e9d405ccb6ca4f3c6adcd to your computer and use it in GitHub Desktop.
External storage path
private val externalStoragePath: String?
@RequiresApi(Build.VERSION_CODES.O)
get() {
val externalFilesDirs = ContextCompat.getExternalFilesDirs(context, null)
if (externalFilesDirs.size == 1 && Environment.isExternalStorageEmulated()) { return null }
return externalFilesDirs.filterNotNull().firstOrNull { file ->
Environment.MEDIA_MOUNTED == EnvironmentCompat.getStorageState(file) &&
!file.path.contains(Environment.getExternalStorageDirectory().path)
}?.path.also { logger.debug("External memory path $it") }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment