AndroidExternalFileWriter


Source link: https://github.com/PrashamTrivedi/AndroidExternalFileWriter

AndroidExternalFileWriter

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. 

Resources

A lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operations.

Custom Gallery for Single and Multiple image pick.

AirTube is an easy to use networking library for Android and Java creating a distributed peer-to-peer overlay mesh network with service discovery and asynchronous message-oriented end-to-end connectivity. By combining these three main features into a small and dedicated library, AirTube frees application developers from worrying about networking details like topologies, IP addresses and port numbers, and simply lets them discover "services" and receive data from it, be it local, remote or anywhere in the global AirTube overlay mesh "cloud".

Android calendar view (like card) Simple and easy to modify.

An image with a close button like Google Messenger attachments.

A parallax listview, scrollview and gridview with zoom support.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes