Coder Social home page Coder Social logo

morristech / androidexternalfilewriter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from prashamtrivedi/androidexternalfilewriter

0.0 0.0 0.0 2.33 MB

A helper class to write files in external android storage, along with it's demo application.

License: Apache License 2.0

Java 55.28% Kotlin 44.72%

androidexternalfilewriter's Introduction

AndroidExternalFileWriter

Download

Android Arsenal

A helper class to write files in external android storage, along with it's demo application.

Class is separately located at https://gist.github.com/PrashamTrivedi/6121924

Maven Availibility

This library is available in JCenter(latest version is 1.4 which is in sync at the time of writing). In your gradle file enter

compile 'com.creativeelites:androidexternalfilewriter:1.4'

Upcoming

We are preparing for storage access framework. Please check Releases page for progress.

How does it work

  1. Create AppExternalFileWriter object with passing context to it.

  2. Use writeDataToFile or writeDataToTimeStampedFile variants as per your wish.

  3. If you want to write a data where a file name should be a time stamp use writeDataToTimeStampedFile variants.

  4. If you want to create a subdirectory use suitable createSubDirectory variants.

  5. If anything is wrong with external storage, like storage not mounted, corrupt, shared as mass storage, not enough space available, or even trying to create a library already created. The class will throw ExternalFileWriterException with the message stating what happened.

  6. If you want to write a data in external cache memory do following.

    • Check the variants of all the methods where it asks for a boolean variable, if you pass true the file operation is done in external cache , otherwise it will be done in normal external memory.
    • If have already created a directory in cache memory get it from createDirectory method, and pass this directory to any method where a parent is required. These methods work same regardless of parent is in external memory or in cache memory.
  7. Checks whether certain directory or file exists on certain location or not with help of isFileExists or isDirectoryExists variants

  8. Deletes entire directory with deleteDirectory method (Note : This method only cares about removing entire directory with its subcontents, if you want to check whether directory is empty or not and use some error message, I recommend to use File.delete() method.)

Description of Variants

  • writeDataToFile Variants

    • Without parent directories
     writeDataToFile(String fileName, byte[] data,boolean inCache);
     writeDataToFile(String fileName, String data,boolean inCache);
    • With parent directories
     writeDataToFile(File parent, String fileName, byte[] data);
     writeDataToFile(File parent, String fileName, String data);
  • writeDataToTimeStampedFile variants

    • Without parent directories
     writeDataToTimeStampedFile(String extension, byte[] data,boolean inCache)
     writeDataToTimeStampedFile(String extension, String data,boolean inCache)
    • With parent directories
     writeDataToTimeStampedFile(String extension, byte[] data)
     writeDataToTimeStampedFile(String extension, String data)
  • createSubDirectory variants

    • Creates subdirectory in any other directory
    	createSubDirectory(File parent, String directoryName)
    • Creates subdirectory in application directory.
     	createSubDirectory(String directoryName,boolean inCache)
  • isDirectoryExists variants

    • Checks whether directory with given name exists in AppDirectory Or Cache directory
     isDirectoryExists(String directoryName, boolean checkInCache)
    • Checks whether directory with given name exists in parentDirectory or not.
     isDirectoryExists(String directoryName, File parentDirectory)
  • isFileExists variants

    • Checks whether file with given name exists in AppDirectory
     isFileExists(String fileName, boolean checkInCache)
    • Check whether directory with given name exists in parentDirectory or not.
     isFileExists(String fileName, File parentDirectory)
  • Delete Directory

    • Deletes given directory with all its subdirectories and its files.
     deleteDirectory(File directory)

Some goodies

  1. getAppDirectory() : File object of created app directory

  2. getExternalStorageDirectory() : File object of external storage directory

  3. getExternalCacheDirectory() : File object of external cache directory

License

   Copyright 2015 Prasham Trivedi
   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.

androidexternalfilewriter's People

Contributors

prashamtrivedi avatar

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.