Skip to content

wshunli/android-copy-assets

Repository files navigation

android-copy-assets

bintray Download Build Status Codacy Badge Author GitHub license

Library for copying assets files and folders to the device

Download

Install android-copy-assets library.

repositories {
    jcenter()
}

dependencies {
    implementation 'com.wshunli.android:android-copy-assets:2.2.0'
}

Check out android-copy-assets releases to see more unstable versions.

How do I use android-copy-assets?

Permission

If you need write file into the EXTERNAL_STORAGE , you should add the permission:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

So if you are targeting Android 6.0+, you need to handle runtime permission request before next step.

Simple usage snippet

CopyAssets.with(this)
        .from("dir1")
        .to(externalPath)
        .copy();

For more information about Data Storage.

More

If you want copy all the files and folders in assets, you can remove the from() method.

CopyAssets.with(this)
        .to(externalPath)
        .copy();

Or the method parameters set to "".

CopyAssets.with(this)
        .from("")
        .to(externalPath)
        .copy();

You can also remove the to() method, while it means copy files and folders to Internal Storage.

CopyAssets.with(this)
        .from("")
        .copy();

CopyListener

android-copy-assets support monitoring file copy progress.

CopyAssets.with(this)
        .to(innerPath)
        .setListener(new CopyListener() {
                @Override
                public void pending(CopyCreator copyCreator, String oriPath, String desPath, List<String> names) {
                Log.d(TAG, "pending: " + names.toString());
                }

                @Override
                public void progress(CopyCreator copyCreator, File currentFile, int copyProgress) {
                Log.d(TAG, "progress: " + copyProgress + "-->currentFile:" + currentFile.getName());
                }

                @Override
                public void completed(CopyCreator copyCreator, Map<File, Boolean> results) {
                Log.d(TAG, "completed: " + results.toString());
                }

                @Override
                public void error(CopyCreator copyCreator, Throwable e) {
                Log.d(TAG, "error: " + e);
                }
        })
        .copy();

Find more details about android-copy-assets in sample.

License

Copyright 2017 wshunli

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.