Skip to content

Commit

Permalink
Don't get external files dir if media isn't mounted (#337)
Browse files Browse the repository at this point in the history
It should work but it's broken on some Tolinos. With this PR we catch the `SecurityException` it throws.
  • Loading branch information
pazos committed Oct 27, 2021
1 parent a1867a0 commit 9d07f02
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ fun Activity.getHeight(): Int {
fun Activity.getSdcardPath(): String? {
val context = this.applicationContext
val packageName = context.packageName
val volumes: Array<out java.io.File> = ContextCompat.getExternalFilesDirs(context, null)
return if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
try {
val volumes: Array<out java.io.File> = ContextCompat.getExternalFilesDirs(context, null)
volumes[1].absolutePath.replace("/Android/data/$packageName/files", "")
} catch (e: Exception) {
null
Expand Down

0 comments on commit 9d07f02

Please sign in to comment.