Fixed: Application crashing below API level 29 when we select the external storage.

* The issue was with the `FileObserver` class constructor we used, which is introduced in SDK 29. As a result, it is not available for older versions, leading to a `NoSuchMethodError` when attempting to access it. This caused the application to crash below API level 29 when selecting external storage.
This commit is contained in:
MohitMaliFtechiz 2023-12-29 15:39:18 +05:30 committed by Kelson
parent 7a73eb797a
commit 24e10caf19

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.zimManager package org.kiwix.kiwixmobile.zimManager
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Build
import android.os.FileObserver import android.os.FileObserver
import io.reactivex.Flowable import io.reactivex.Flowable
import io.reactivex.functions.BiFunction import io.reactivex.functions.BiFunction
@ -63,11 +64,20 @@ class Fat32Checker constructor(
} }
private fun fileObserver(it: String): FileObserver = private fun fileObserver(it: String): FileObserver =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
object : FileObserver(File(it), MOVED_FROM or DELETE) { object : FileObserver(File(it), MOVED_FROM or DELETE) {
override fun onEvent(event: Int, path: String?) { override fun onEvent(event: Int, path: String?) {
requestCheckSystemFileType.onNext(Unit) requestCheckSystemFileType.onNext(Unit)
} }
}.apply { startWatching() } }.apply { startWatching() }
} else {
@Suppress("DEPRECATION")
object : FileObserver(it, MOVED_FROM or DELETE) {
override fun onEvent(event: Int, path: String?) {
requestCheckSystemFileType.onNext(Unit)
}
}.apply { startWatching() }
}
private fun toFileSystemState(it: String) = private fun toFileSystemState(it: String) =
when { when {