Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
ru.bartwell:safhelper
Advanced tools
Open source Android library for files writing on SD card.
SafHelper using Storage Access Framework (SAF) to retrieve permission, create directories and write files on SD card.
Add dependency in build.gradle:
compile 'ru.bartwell:safhelper:1.0.0'
private lateinit var safHelper: SafHelper
private fun onButtonClick() {
writeFile(true)
}
private fun writeFile(requestPermissions: Boolean) {
val userFile = File(main_path.text.toString())
if (userFile.parent == null) {
showToast("Wrong path")
} else {
safHelper = SafHelper(this, userFile.parent)
if (safHelper.isApplicable()) {
if (safHelper.isPermissionGranted()) {
try {
if (safHelper.mkdirs(userFile.parent)) {
val outputStream = safHelper.createFile(userFile.path)
outputStream.use {
it.write("Text in the file".toByteArray())
}
showToast("Success")
}
} catch (e: Exception) {
e.printStackTrace()
showToast("Error: " + e.message)
}
} else {
if (requestPermissions) {
safHelper.requestPermissions(this)
} else {
showToast("Permissions not granted")
}
}
} else {
showToast("File is not on SD Card or Android version < 5.0")
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
if (safHelper.onActivityResult(this, requestCode, resultCode, resultData)) {
writeFile(false)
}
}
Copyright © 2018 Artem Bazhanov
SafHelper is provided under an Apache 2.0 License.
FAQs
Open source Android library for files writing on SD card.
We found that ru.bartwell:safhelper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.