All Projects → tonyofrancis → Fetch

tonyofrancis / Fetch

Licence: apache-2.0
The best file downloader library for Android

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Fetch

Fast Android Networking
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
Stars: ✭ 5,346 (+375.62%)
Mutual labels:  networking, downloader, okhttp, internet, downloadmanager
Kotlin Networking
Kotlin Networking - An elegant networking library written in Kotlin
Stars: ✭ 88 (-92.17%)
Mutual labels:  networking, okhttp, internet
FireFiles
Powerful Android File Manager for everything that runs on Android OS (Android TV, Android Watch, Mobile, etc)
Stars: ✭ 37 (-96.71%)
Mutual labels:  application, android-development, android-tv
Snipit
Snipit allows you to capture and save interesting sections from any source of information. Be it textbooks, journals, computer screens, photographs, flyers, writings on a whiteboard, etc.
Stars: ✭ 70 (-93.77%)
Mutual labels:  application, mobile, app
Mobly
E2E test framework for tests with complex environment requirements.
Stars: ✭ 424 (-62.28%)
Mutual labels:  networking, mobile, android-development
Go4droid
build an android app (with go bindings) in Docker
Stars: ✭ 32 (-97.15%)
Mutual labels:  gradle, android-development
Quiz
An android application which uses Open Trivia Api.
Stars: ✭ 34 (-96.98%)
Mutual labels:  gradle, retrofit
Todo app open source
📱 an app to annotate tasks made with Flutter using MobX
Stars: ✭ 40 (-96.44%)
Mutual labels:  application, app
Rxdownloader
- Reactive Extension Library for Android to download files
Stars: ✭ 40 (-96.44%)
Mutual labels:  downloader, internet
Androidall
Android 程序员需要掌握的技术栈:数据结构算法、程序架构、设计模式、性能优化、插件化、热更新、Kotlin、NDK、Jetpack,以及常用的开源框架源码分析如 Flutter、Router、RxJava、Glide、LeakCanary、Dagger2、Retrofit、OkHttp、ButterKnife 等
Stars: ✭ 849 (-24.47%)
Mutual labels:  okhttp, retrofit
Easygo
基于Kotlin、OkHttp的声明式网络框架,像写HTML界面一样写网络调用代码
Stars: ✭ 40 (-96.44%)
Mutual labels:  okhttp, retrofit
Rntimerexample
📱 React Native + Mobx sample app
Stars: ✭ 40 (-96.44%)
Mutual labels:  mobile, app
Awesome Third Library Source Analysis
📖 Deep understanding of popular open source library source code (optimizing...)
Stars: ✭ 866 (-22.95%)
Mutual labels:  okhttp, retrofit
Kotlin Life
App界的一股清流 音视频vr应有尽有 完全按照Material design规范设计的App (written with java and Kotlin)
Stars: ✭ 864 (-23.13%)
Mutual labels:  okhttp, app
Hunter
A fast, incremental, concurrent framework to develop compile plugin for android project to manipulate bytecode
Stars: ✭ 999 (-11.12%)
Mutual labels:  gradle, okhttp
Mvvmhabitcomponent
👕基于MVVMHabit框架,结合阿里ARouter打造的一套Android MVVM组件化开发方案
Stars: ✭ 857 (-23.75%)
Mutual labels:  okhttp, retrofit
Downloader
Downloader for android with pause, resume, cancel, queue options
Stars: ✭ 40 (-96.44%)
Mutual labels:  downloader, downloadmanager
Meteorite
一个基于Android MVP的简单明了的指引性通用架构,目的是帮助更多的开发者去全面了解实践开发相关的各种技术,快速搭建属于自已的APP。这个项目涉及到如下技术的实际应用:1、MVP 2、网络请求(Novate基于rxjava,okhttp,retrofit封装架构)3、DbFlow(可保存文件入SD卡) 4、6.0权限申请 5、XRecyclerView 6、万能Adapter7、异常处理 8、日志打印 9、屏幕适配 10、代码混淆 11、多渠道打包 12、内存泄露检测 13、热修复 14、升级更新 15、极光推送 工程更新完善中……欢迎关注 @特别感谢ZJ.Y的Logo支持。
Stars: ✭ 49 (-95.64%)
Mutual labels:  okhttp, retrofit
Formant Analyzer
iOS application for finding formants in spoken sounds
Stars: ✭ 43 (-96.17%)
Mutual labels:  application, app
Mzdownloadmanager
This download manager uses NSURLSession api to download files. It can download multiple files at a time. It can download large files if app is in background. It can resume downloads if app was quit.
Stars: ✭ 1,061 (-5.6%)
Mutual labels:  downloader, downloadmanager

Build Status Download Android Arsenal License

ScreenShot

Overview

Fetch is a simple, powerful, customizable file download manager library for Android.

ScreenShot

Features

  • Simple and easy to use API.
  • Continuous downloading in the background.
  • Concurrent downloading support.
  • Ability to pause and resume downloads.
  • Set the priority of a download.
  • Network-specific downloading support.
  • Ability to retry failed downloads.
  • Ability to group downloads.
  • Easy progress and status tracking.
  • Download remaining time reporting (ETA).
  • Download speed reporting.
  • Save and Retrieve download information anytime.
  • Notification Support.
  • Storage Access Framework, Content Provider and URI support.
  • 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"/>

Also, as you are going to use Internet to download files. We need to add the Internet access permissions in the Manifest.

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

How to use Fetch

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

implementation "com.tonyodev.fetch2:fetch2:3.0.12"

Androidx use:

implementation "androidx.tonyodev.fetch2:xfetch2:3.1.6"

Next, get an instance of Fetch and request a download.

public class TestActivity extends AppCompatActivity {

    private Fetch fetch;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

 FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(this)
                .setDownloadConcurrentLimit(3)
                .build();

        fetch = Fetch.Impl.getInstance(fetchConfiguration);

        String url = "http:www.example.com/test.txt";
        String file = "/downloads/test.txt";
        
        final Request request = new Request(url, file);
        request.setPriority(Priority.HIGH);
        request.setNetworkType(NetworkType.ALL);
        request.addHeader("clientKey", "SD78DF93_3947&MVNGHE1WONG");
        
        fetch.enqueue(request, updatedRequest -> {
            //Request was successfully enqueued for download.
        }, error -> {
            //An error occurred enqueuing the request.
        });

    }
}

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

FetchListener fetchListener = new FetchListener() {
    @Override
    public void onQueued(@NotNull Download download, boolean waitingOnNetwork) {
        if (request.getId() == download.getId()) {
            showDownloadInList(download);
        }
    }

    @Override
    public void onCompleted(@NotNull Download download) {

    }

    @Override
    public void onError(@NotNull Download download) {
        Error error = download.getError();
    }

    @Override
    public void onProgress(@NotNull Download download, long etaInMilliSeconds, long downloadedBytesPerSecond) {
        if (request.getId() == download.getId()) {
            updateDownload(download, etaInMilliSeconds);
        }
        int progress = download.getProgress();
    }

    @Override
    public void onPaused(@NotNull Download download) {

    }

    @Override
    public void onResumed(@NotNull Download download) {

    }

    @Override
    public void onCancelled(@NotNull Download download) {

    }

    @Override
    public void onRemoved(@NotNull Download download) {

    }

    @Override
    public void onDeleted(@NotNull Download download) {

    }
};

fetch.addListener(fetchListener);

//Remove listener when done.
fetch.removeListener(fetchListener);

Fetch supports pausing and resuming downloads using the request's id. A request's id is a unique identifier that maps a request to a Fetch Download. A download returned by Fetch will have have an id that matches the request id that started the download.

Request request1 = new Request(url, file);
Request request2 = new Request(url2, file2);

fetch.pause(request1.getId());

...

fetch.resume(request2.getId());

You can query Fetch for download information in several ways.

//Query all downloads
fetch.getDownloads(new Func<List<? extends Download>>() {
    @Override
        public void call(List<? extends Download> downloads) {
            //Access all downloads here
        }
});

//Get all downloads with a status
fetch.getDownloadsWithStatus(Status.DOWNLOADING, new Func<List<? extends Download>>() {
    @Override
        public void call(List<? extends Download> downloads) {
            //Access downloads that are downloading
        }
});

// You can also access grouped downloads
int groupId = 52687447745;
fetch.getDownloadsInGroup(groupId, new Func<List<? extends Download>>() {
    @Override
      public void call(List<? extends Download> downloads) {
              //Access grouped downloads
      }
});

When you are done with an instance of Fetch, simply release it.

//do work

fetch.close();

//do more work

Downloaders

By default Fetch uses the HttpUrlConnection client via the HttpUrlConnectionDownloader to download requests. Add the following Gradle dependency to your application's build.gradle to use the OkHttp Downloader instead. You can create your custom downloaders if necessary. See the Java docs for details.

implementation "com.tonyodev.fetch2okhttp:fetch2okhttp:3.0.12"

Androidx use:

implementation "androidx.tonyodev.fetch2okhttp:xfetch2okhttp:3.1.6"

Set the OkHttp Downloader for Fetch to use.

OkHttpClient okHttpClient = new OkHttpClient.Builder().build();

FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(this)
    .setDownloadConcurrentLimit(10)
    .setHttpDownloader(new OkHttpDownloader(okHttpClient))
    .build();

Fetch fetch = Fetch.Impl.getInstance(fetchConfiguration);

RxFetch

If you would like to take advantage of RxJava2 features when using Fetch, add the following gradle dependency to your application's build.gradle file.

implementation "com.tonyodev.fetch2rx:fetch2rx:3.0.12"

Androidx use:

implementation "androidx.tonyodev.fetch2rx:xfetch2rx:3.1.6"

RxFetch makes it super easy to enqueue download requests and query downloads using rxJava2 functional methods.

FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(this).build();
Rxfetch rxFetch = RxFetch.Impl.getInstance(fetchConfiguration);

rxFetch.getDownloads()
        .asFlowable()
        .subscribe(new Consumer<List<Download>>() {
            @Override
            public void accept(List<Download> downloads) throws Exception {
                //Access results
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                //An error occurred
                final Error error = FetchErrorUtils.getErrorFromThrowable(throwable);
            }
        });

FetchFileServer

Introducing the FetchFileServer. The FetchFileServer is a lightweight TCP File Server that acts like an HTTP file server designed specifically to share files between Android devices. You can host file resources with the FetchFileServer on one device and have to Fetch download Files from the server on another device. See the sample app for more information. Wiki on FetchFileServer will be added in the coming days.

Start using FetchFileServer by adding the gradle dependency to your application's build.gradle file.

implementation "com.tonyodev.fetch2fileserver:fetch2fileserver:3.0.12"

Androidx use:

implementation "androidx.tonyodev.fetch2fileserver:xfetch2fileserver:3.1.6"

Start a FetchFileServer instance and add resource files that it can serve to connected clients.

public class TestActivity extends AppCompatActivity {

    FetchFileServer fetchFileServer;
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fetchFileServer = new FetchFileServer.Builder(this)
                .build();
        
        fetchFileServer.start(); //listen for client connections

        File file = new File("/downloads/testfile.txt");
        FileResource fileResource = new FileResource();
        fileResource.setFile(file.getAbsolutePath());
        fileResource.setLength(file.length());
        fileResource.setName("testfile.txt");
        fileResource.setId(UUID.randomUUID().hashCode());
        
        fetchFileServer.addFileResource(fileResource);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        fetchFileServer.shutDown(false);
    }
}

Downloading a file from a FetchFileServer using the Fetch is easy.

public class TestActivity extends AppCompatActivity {

    Fetch fetch;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(this)
                .setFileServerDownloader(new FetchFileServerDownloader()) //have to set the file server downloader
                .build();
        fetch = Fetch.Impl.getInstance(fetchConfiguration);
        fetch.addListener(fetchListener);

        String file = "/downloads/sample.txt";
        String url = new FetchFileServerUrlBuilder()
                .setHostInetAddress("127.0.0.1", 6886) //file server ip and port
                .setFileResourceIdentifier("testfile.txt") //file resource name or id
                .create();
        Request request = new Request(url, file);
        fetch.enqueue(request, request1 -> {
            //Request enqueued for download
        }, error -> {
            //Error while enqueuing download
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        fetch.addListener(fetchListener);
    }

    @Override
    protected void onPause() {
        super.onPause();
        fetch.removeListener(fetchListener);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        fetch.close();
    }

    private FetchListener fetchListener = new AbstractFetchListener() {
        @Override
        public void onProgress(@NotNull Download download, long etaInMilliSeconds, long downloadedBytesPerSecond) {
            super.onProgress(download, etaInMilliSeconds, downloadedBytesPerSecond);
            Log.d("TestActivity", "Progress: " + download.getProgress());
        }

        @Override
        public void onError(@NotNull Download download) {
            super.onError(download);
            Log.d("TestActivity", "Error: " + download.getError().toString());
        }

        @Override
        public void onCompleted(@NotNull Download download) {
            super.onCompleted(download);
            Log.d("TestActivity", "Completed ");
        }
    };
}

Fetch1 Migration

Migrate downloads from Fetch1 to Fetch2 using the migration assistant. Add the following gradle dependency to your application's build.gradle file.

implementation "com.tonyodev.fetchmigrator:fetchmigrator:3.0.12"

Androidx use:

implementation "androidx.tonyodev.fetchmigrator:xfetchmigrator:3.1.6"

Then run the Migrator.

        if (!didMigrationRun()) {
            //Migration has to run on a background thread
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        final List<DownloadTransferPair> transferredDownloads = FetchMigrator.migrateFromV1toV2(getApplicationContext(), APP_FETCH_NAMESPACE);
                        //TODO: update external references of ids
                        for (DownloadTransferPair transferredDownload : transferredDownloads) {
                            Log.d("newDownload", transferredDownload.getNewDownload().toString());
                            Log.d("oldId in Fetch v1", transferredDownload.getOldID() + "");
                        }
                        FetchMigrator.deleteFetchV1Database(getApplicationContext());
                        setMigrationDidRun(true);
                        //Setup and Run Fetch2 after the migration
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        } else {
            //Setup and Run Fetch2  normally
        }

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].