mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Merge pull request #1394 from kiwix/feature/macgills/#1386-partial-fix-spinner
Storage Not Accessible in API 28 #1385 - partial fix in StorageDevice…
This commit is contained in:
commit
0c4a2005e4
@ -21,10 +21,12 @@ package eu.mhutti1.utils.storage
|
|||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.StatFs
|
import android.os.StatFs
|
||||||
|
import android.util.Log
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileReader
|
import java.io.FileReader
|
||||||
import java.io.FileWriter
|
import java.io.FileWriter
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
const val LOCATION_EXTENSION = "storageLocationMarker"
|
const val LOCATION_EXTENSION = "storageLocationMarker"
|
||||||
|
|
||||||
@ -73,16 +75,20 @@ data class StorageDevice(
|
|||||||
// Create unique file to identify duplicate devices.
|
// Create unique file to identify duplicate devices.
|
||||||
private fun createLocationCode() {
|
private fun createLocationCode() {
|
||||||
if (!getLocationCodeFromFolder(file)) {
|
if (!getLocationCodeFromFolder(file)) {
|
||||||
File(file.path, ".$LOCATION_EXTENSION").let { locationCode ->
|
File(file, ".$LOCATION_EXTENSION").let { locationCode ->
|
||||||
|
try {
|
||||||
locationCode.createNewFile()
|
locationCode.createNewFile()
|
||||||
FileWriter(locationCode).use { it.write(file.path) }
|
FileWriter(locationCode).use { it.write(file.path) }
|
||||||
|
} catch (ioException: IOException) {
|
||||||
|
Log.d("StorageDevice", "could not write file $file", ioException)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there is already a device code in our path
|
// Check if there is already a device code in our path
|
||||||
private fun getLocationCodeFromFolder(folder: File): Boolean {
|
private fun getLocationCodeFromFolder(folder: File): Boolean {
|
||||||
val locationCode = File(folder.path, ".$LOCATION_EXTENSION")
|
val locationCode = File(folder, ".$LOCATION_EXTENSION")
|
||||||
if (locationCode.exists()) {
|
if (locationCode.exists()) {
|
||||||
try {
|
try {
|
||||||
BufferedReader(FileReader(locationCode)).use { br ->
|
BufferedReader(FileReader(locationCode)).use { br ->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user