Giter Site home page Giter Site logo

Comments (1)

karner avatar karner commented on July 20, 2024

The project I'm working on is at the moment not publicly available, but this is the code which processes media folders by checking the filename. If it ends with "-media" which is the naming for the media folders it will create the folder on the sd card and copy all containing files over to the sdcard directory. This currently only works for files, not for nested directories. I can't commit this to this repo at the moment, but this is the new method copyFormMedia() and the updated method copyForms() from GeoODK.java

private void copyFormMedia(String foldername){
    AssetManager assetManager = getAssets();
    String[] assetList = null;
    try {
        assetList = assetManager.list("forms" + File.separator + foldername);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    for (String assetName : assetList) {
        InputStream in = null;
        OutputStream out = null;
        File outFile = new File(FORMS_PATH + File.separator + foldername + File.separator + assetName);
        if (!outFile.exists()) {
            try {
                in = assetManager.open("forms" + File.separator + foldername + File.separator + assetName);
                out = new FileOutputStream(FORMS_PATH + File.separator + foldername + File.separator + assetName);
                copyFile(in, out);
                in.close();
                out.flush();
                out.close();
                in = null;
                out = null;

            } catch (IOException e) {
                Log.e("tag", "Failed to copy asset file: " + FORMS_PATH + File.separator, e);
            }
        }
    }
}

private void copyForms(String[] forms) {
    AssetManager assetManager = getAssets();
    InputStream in = null;
    OutputStream out = null;
    for (int i = 0; forms.length > i; i++) {
        String filename = forms[i];
        File form_file = new File(FORMS_PATH, filename);
        if (filename.endsWith("-media")) {
            boolean success = true;
            if (!form_file.exists()) {
                success = form_file.mkdir();
            }
            if (!success){
                Log.e("tag", "Failed to create media folder: " + FORMS_PATH + File.separator + filename);
                continue;
            }
            copyFormMedia(filename);
        } else {
            if (!form_file.exists()) {
                try {
                    in = assetManager.open("forms/" + filename);
                    out = new FileOutputStream(FORMS_PATH + File.separator + filename);
                    copyFile(in, out);
                    in.close();
                    out.flush();
                    out.close();
                    in = null;
                    out = null;

                } catch (IOException e) {
                    Log.e("tag", "Failed to copy asset file: " + FORMS_PATH + File.separator + forms[i], e);
                }
            }
        }
        System.out.println(forms[i]);
    }

}

from collect.

Related Issues (20)

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.