SafHelper

Open source Android library for files writing on SD card.

Лицензия

Лицензия

Группа

Группа

ru.bartwell
Идентификатор

Идентификатор

safhelper
Последняя версия

Последняя версия

1.0.1
Дата

Дата

Тип

Тип

aar
Описание

Описание

SafHelper
Open source Android library for files writing on SD card.
Ссылка на сайт

Ссылка на сайт

https://github.com/bartwell/SafHelper
Система контроля версий

Система контроля версий

https://github.com/bartwell/SafHelper.git

Скачать safhelper

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/ru.bartwell/safhelper/ -->
<dependency>
    <groupId>ru.bartwell</groupId>
    <artifactId>safhelper</artifactId>
    <version>1.0.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/ru.bartwell/safhelper/
implementation 'ru.bartwell:safhelper:1.0.1'
// https://jarcasting.com/artifacts/ru.bartwell/safhelper/
implementation ("ru.bartwell:safhelper:1.0.1")
'ru.bartwell:safhelper:aar:1.0.1'
<dependency org="ru.bartwell" name="safhelper" rev="1.0.1">
  <artifact name="safhelper" type="aar" />
</dependency>
@Grapes(
@Grab(group='ru.bartwell', module='safhelper', version='1.0.1')
)
libraryDependencies += "ru.bartwell" % "safhelper" % "1.0.1"
[ru.bartwell/safhelper "1.0.1"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
org.jetbrains.kotlin : kotlin-stdlib jar 1.2.70
com.android.support » appcompat-v7 jar 27.1.0

Модули Проекта

Данный проект не имеет модулей.

SafHelper

Open source Android library for files writing on SD card.

Features

SafHelper using Storage Access Framework (SAF) to retrieve permission, create directories and write files on SD card.

Integration

Add dependency in build.gradle:

compile 'ru.bartwell:safhelper:1.0.0'

Usage

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)
    }
}

License

Copyright © 2018 Artem Bazhanov

SafHelper is provided under an Apache 2.0 License.

Версии библиотеки

Версия
1.0.1
1.0.0