Oh my SAF - Android simple SAF helper (https://github.com/Trumeet/OhMySAF [2019])
Find a file
YuutaW 9bb51f7140 fix: fix version
Signed-off-by: YuutaW <17158086+Trumeet@users.noreply.github.com>
2019-04-19 10:55:44 -07:00
app feat(library/demo): add some simple APIs 2019-04-19 10:43:22 -07:00
gradle/wrapper First Commit 2019-04-18 19:36:25 -07:00
ohmysaf feat(library/demo): add some simple APIs 2019-04-19 10:43:22 -07:00
.gitignore First Commit 2019-04-18 19:36:25 -07:00
.travis.yml First Commit 2019-04-18 19:36:25 -07:00
build.gradle fix: fix version 2019-04-19 10:55:44 -07:00
deploy_repo.sh First Commit 2019-04-18 19:36:25 -07:00
gradle.properties First Commit 2019-04-18 19:36:25 -07:00
gradlew First Commit 2019-04-18 19:36:25 -07:00
gradlew.bat First Commit 2019-04-18 19:36:25 -07:00
README.md docs: fix the maven url 2019-04-19 10:50:15 -07:00
settings.gradle First Commit 2019-04-18 19:36:25 -07:00

Oh My SAF

Android SAF helper.

Implement

  1. Add maven.yuuta.dev repo to your module

  2. Add dependency:

implementation 'moe.yuuta.ohmysaf:ohmysaf:<the latest version>'

Main Features

  • Faster migrate - If you have an old project which uses java.io.File a lot and you would like to migrate to SAF, OMG. By using OhMySAF, you can just continue using File with a little hack.

Faster Migrate

Imagine that you have an old project and its file operation codes look like:

File theFxxkFile = new File("xxx/xxx");
if (theFxxkFile.isFile()) {
    theFxxkFile.delete();
    theFxxkFile.mkdir(); // In fact, SAF does not support that.
}

If you want to switch to SAF, the normal code will look like:

// Assume that you've got the URI
DocumentFile theFxxkFile = DocumentFile.fromTreeUri(context, uri);
if (theFxxkFile.isFile()) {
    theFxxkFile.delete();
    // .....
}

One day you discovered OhMySAF, your problem is solved:

// Assume that you've got the URI

// Magic
File theFxxkFile = OhMySAF.ohMyTree(context, uri);

// Just KEEP these old codes!
if (theFxxkFile.isFile()) {
    theFxxkFile.delete();
    theFxxkFile.mkdir(); // In fact, SAF does not support that.
}

Extend usages

Some APIs don't work with SafFile. In these cases, you should cast the returned File to SafFile and use extended APIs.

SafFile theMagic = OhMySAF.ohMyUri(context, uri);

Get Android Uri

It returns the Android Uri and you can do ANYTHING you want with it.

final Uri uri = theMagic.getAndroidUri();

Open input / output stream

The Java FileInputStream and FileOutputStream does not work with the file directly. Talk is cheap, let's show you the code:

final OutputStream stream = theMagic.openOutputStream(this, "w");
stream.close();

Licenses

Apache 2.0