Giter Club home page Giter Club logo

kio's Introduction

Kio

基于Kotlin的Android通用文件操作库

导入依赖

将其添加到根目录的 build.gradle.kts 文件中

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        mavenCentral()
        maven("https://jitpack.io")
    }
}

在项目 build.gradle.kts 添加依赖

dependencies {
    implementation("com.github.limao996:Kio:1.1.1")
}

使用方法/示例

Activity 中实例化 Kio 对象并注册 onActivityResult 回调

class MainActivity : AppCompatActivity() {
    private val kio = Kio(this)

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        kio.onActivityResult(requestCode, resultCode, data)
    }
}

调用 kio.open 打开 KFile 对象

// 返回 [KStorageFile] 对象
kio.open("/sdcard/test.txt")

// 返回 [KStorageFile] 对象
kio.open(File("/sdcard/test.txt"))

// 根据情况会返回 [KStorageFile] 或 [KDocumentFile]
kio.open("/sdcard/Android/data/bin.mt.plus/test.txt")

// 返回 [KUriFile] 对象
kio.open(intent.data!!)

处理文件操作所需权限

// 检查并申请权限,回调事件返回结果
file.checkAndRequestPermission { granted -> }

// 检查权限
file.checkPermission()

// 申请权限
file.requestPermission { granted -> }

// 释放权限,返回结果
// 目前仅 [KDocumentFile] 支持
file.releasePermission()

// [KUriFile] 不支持处理权限

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.