Fetch


Source link: https://github.com/tonyofrancis/Fetch

Fetch

A better in app Download Manager for Android.

Overview

Fetch is a simple yet powerful Android library that allows you to manage downloads more efficiently in your Android apps. It uses a background service on the device to download and maintain requests.

Features

  • Simple and easy to use API.
  • Continuous downloading in the background.
  • Concurrent Downloads Support.
  • Ability to pause and resume downloads.
  • Set the priority of a download request.
  • Ability to retry failed downloads.
  • Easy progress and status tracking.
  • And more...

Prerequisites

If you are saving downloads outside of your application's sandbox, you will need to add the following storage permissions to your application's manifest. For Android SDK version 23(M) and above, you will also need to explicitly request these permissions from the user.

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

How to use Fetch

Using Fetch is easy! Just add the Gradle dependency to your application's build.gradle file.

compile 'com.tonyodev.fetch:fetch:1.1.4'

Next, get an instance of Fetch and request a download. A unique ID will be returned for each request.

public class MainActivity extends AppCompatActivity {

@Override
  public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

 Fetch fetch = Fetch.newInstance(this);

...

Request request = new Request(url,dirPath,fileName);

long downloadId = fetch.enqueue(request);

 if(downloadId != Fetch.ENQUEUE_ERROR_ID) {

//Download was successfully queued for download.  
}

 
}
  
}

Tracking a download's progress and status is very easy with Fetch. Simply add a FetchListener to your instance, and the listener will be notified whenever a download's status or progress changes.

fetch.addFetchListener(new FetchListener() {

@Override
  public void onUpdate(long id, int status, int progress, long downloadedBytes, long fileSize, int error) {

  if(downloadId == id && status == Fetch.STATUS_DOWNLOADING) {

  progressBar.setProgress(progress);

 ...

}
else if(error != Fetch.NO_ERROR) {

//An error occurred 

if(error == Fetch.ERROR_HTTP_NOT_FOUND) {

 //handle error

}

  
}

  
}

}
);

Fetch supports pausing and resuming downloads. If a download request fails, you can opt to retry.

...  fetch.pause(downloadId);
  ...  fetch.resume(downloadId);
  ...  fetch.retry(downloadId);

When you are done with an instance of Fetch, simply release it. It is important that you release instances of fetch to prevent memory leaks.

//do work  fetch.release();
  //do more work

Changing Fetch settings are easy!

new Fetch.Settings(getApplicationContext())  .setAllowedNetwork(Fetch.NETWORK_ALL)  .enableLogging(true)  .setConcurrentDownloadsLimit(3)  .apply();

Contribute

Fetch can only get better if you make code contributions. Found a bug? Report it. Have a feature idea you'd love to see in Fetch? Contribute to the project!

License

Copyright (C) 2017 Tonyo Francis.  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

SimpleAB is a framework to help you A/B test your Android applications with no hassle. A/B testing should be as simple as it needs to, and if you're not interested in handling huge SDKs and understanding complex dashboards and documentation articles, SimpleAB is the tool you was looking for.

The project makes easy animations by entering Activity or Fragment

Trigger is a back-port of JobScheduler mechanism from Android Lollipop.

Android layout that simulates physics using JBox2D. Simply add views, enable physics, and watch them fall!

AsyncManager hopes to keep management of background threads as simple as possible, by keeping the creation and termination of background tasks to just one API call respectively. Callback, which will be processed on the UI thread, can be overridden to process the result returned from the background operation.

Nox

Nox is an Android library created to show a custom view with some NoxItem instances inside which are drawn following a shape indicated by the library user. You can create you own Shape implementations if you want, by default there are some interesting Shape implementations to show NoxItem instances following a circular, spiral or linear shape.

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