This is a utility API for File Management.
If you don't need to use WorkManager + Coroutine for file CRUD, check FilemanLite repository first.
I did this Library because I had a problem with multi threading writing/reading which I needed to guarantee the log chronology and to keep the job working even when the app is not running anymore.
In build.graddle (app)
dependencies {
implementation 'com.3xcool:fileman:$LATEST_VERSION'
}
Use FilemanDrivers enum class:
- SandBox: Where the app is installed (can't be accessed by other apps)
- Internal: Device storage (can be accessed by other apps)
- External: SD Card if available
Don't call these functions on the Main Thread to avoid UI freeze.
Fileman.write(fileContent: String, context: Context, drive: Int, folder: String, filename: String, append: Boolean)
Fileman.read(context: Context, drive: Int, folder: String, filename: String)
Fileman.delete(context: Context, drive: Int, folder: String, filename: String)
For WorkManager use FilemanWM class instead.
filemanWM = FilemanWM(context, viewLifecycleOwner)
Obs: Launch and Async are Coroutine nomenclatures, see Kotlin Coroutine to see the difference.
val res = filemanWM.writeLaunch("filecontent", context, drive, folder, filename, append = true, withTimeout = true, timeout = 10000L)
//return a FilemanFeedback Class.
Get the return from filemanFeedback and errorFeedback LiveData.
filemanWM.filemanFeedback.observe(this, Observer { output ->
updateText(output)
})
filemanWM.errorFeedback.observe(this, Observer { output ->
updateText(output)
})
cancelWorkById(), cancelAllWorks() and pruneWork()
Copyright 2020 André Filgueiras
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.