Netroid

Netroid is a Http Framework for Android that based on Volley
Alternatives To Netroid
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Cpp Httplib9,185
13 hours ago1August 03, 202215mitC++
A C++ header-only HTTP/HTTPS server and client library
Async Http Client6,0761,83146813 days ago126October 13, 201690otherJava
Asynchronous Http and WebSocket Client library for Java
Urllib33,31337,7175,5403 hours ago71March 16, 2022119mitPython
Python HTTP library with thread-safe connection pooling, file post support, user friendly, and more.
Reading Code Of Nginx 1.9.23,211
2 years ago11gpl-3.0C
nginx-1.9.2源码通读分析注释,带详尽函数中文分析注释以及相关函数流程调用注释,最全面的nginx源码阅读分析中文注释,更新完毕
Evpp3,121
5 months ago130bsd-3-clauseC++
A modern C++ network library for developing high performance network services in TCP/UDP/HTTP protocols.
Onion1,872
7 months ago59otherC
C library to create simple HTTP servers and Web Applications.
Restclient Cpp1,412
6 months ago28mitC++
C++ client for making HTTP/REST requests
Brynet904
a month ago26mitC++
A Header-Only cross-platform C++ TCP network library . We can use vcpkg(https://github.com/Microsoft/vcpkg/tree/master/ports/brynet) install brynet.
Volley Demo903
7 years ago4Java
An demonstration of Volley - HTTP library announced by google in I/O 2013. Illustrates, JSONRequest,StringRequest, Image caching.
Tiny Http792177832 months ago29February 25, 202244apache-2.0Rust
Low level HTTP server library in Rust
Alternatives To Netroid
Select To Compare


Alternative Project Comparisons
Readme

Netroid library for Android

Netroid is a http library for Android that based on Volley, That purpose is make your android development easier than before, provide fast, handly, useful way to do async http operation by background thread.

Feature

1. Base async http interaction.

As most android apps done, Netroid allow you to retrive data over http with background thread, exchange invoke result to main thread.

2. Response cache base disk.

Netroid can cache your http response to disk and the cache expire time was configurable.

3. Image loading solution.

Provide a powerful solution of image load, used LruImageCache as bitmap memory cache.

4. Big file download solution.

Provide file download management, allows create, pause, continue, discard operation with download task, also download progress callback.

principle

When Netroid startup, it create lots of thread that amount specify by developer, each thread will block with Request Queue, after a new request comes, whether thread will be awake then perform http operation, finally it back to block status if that perform is done.

Basic usage

The main entry of Netroid is RequestQueue, we highly recommnd you init it with Application and always let it stand with singleton :

public class YourApplication extends Application {

    public void onCreate() {
        super.onCreate();

        // you can choose HttpURLConnection or HttpClient to execute request.
        Network network = new BasicNetwork(new HurlStack(Const.USER_AGENT, null), HTTP.UTF_8);

        // you can specify parallel thread amount, here is 4.
        // also instance the DiskBaseCache by your settings.
        RequestQueue mQueue = new RequestQueue(network, 4,
            new DiskCache(new File(ctx.getCacheDir(), Const.HTTP_DISK_CACHE_DIR_NAME), Const.HTTP_DISK_CACHE_SIZE));

        // start and waiting requests.
        mQueue.start();
    }

}

In anywhere, the only one you should do just take the RequestQueue instance, then simply add your request instance into RequestQueue :

StringRequest request = new StringRequest(url, new Listener<String>() {
    ProgressDialog mPrgsDialog;

    @Override
    public void onPreExecute() {
        mPrgsDialog = ProgressDialog.show(Activity.this, null, "loading...", true, true);
    }

    // cancel the dialog with onFinish() callback
    @Override
    public void onFinish() {
        mPrgsDialog.cancel();
    }

    @Override
    public void onSuccess(String response) {
        Toast.makeText(Activity.this, "response is : " + response, 2000).show();
    }

    @Override
    public void onError(NetroidError error) {
        Toast.makeText(Activity.this, error.getMessage(), 2000).show();
    }

    @Override
    public void onCancel() {
        Toast.makeText(Activity.this, "request was cancel", 2000).show();
    }
});

// add the request to RequestQueue, will execute quickly if has idle thread
mQueue.add(request);

Do not forget add internet permission to the AndroidManifest.xml file :

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

ImageLoader

Similarly, ImageLoader should be singleton and also init with Application :

public class YourApplication extends Application {

    public void onCreate() {
        super.onCreate();

        RequestQueue mQueue = ...;

        // SelfImageLoader is your implementation that extends by ImageLoader.
        // you can create a memory cache policy within ImageLoader.
        ImageLoader mImageLoader = new SelfImageLoader(
            mQueue, new BitmapImageCache(Const.HTTP_MEMORY_CACHE_SIZE));
    }

    // the method you'll perform when you want to fill a single ImageView with network image.
    public void displayImage(String url, ImageView imageView) {
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView, 0, 0);
        mImageLoader.get(url, listener, 0, 0);
    }

    // we bring you the NetworkImageView to load network images when it's inside of ListView or GridView.
    public void displayImage(String url, NetworkImageView imageView) {
        imageView.setImageUrl(url, mImageLoader);
    }

}

FileDownloader

As always singleton, FileDownloader would be the same :

public class YourApplication extends Application {

    public void onCreate() {
        super.onCreate();

        RequestQueue mQueue = ...;

        // specify the parallel download task count, less than 3 is recommended.
        FileDownloader mFileDownloader = new FileDownloader(mQueue, 1);
    }

    // add a new download task, take the DownloadController instance.
    public FileDownloader.DownloadController addFileDownload(String storeFilePath, String url, Listener<Void> listener) {
        return mFileDownloader.add(storeFilePath, url, listener);
    }

}

With DownloadController, you can get the task status such as waiting downloading, finish, also you can trun the task to pause, continue, discard status. the Listener.onProgressChange() will inform you the download progress.

Integration

Download the latest JAR or grab via Maven :

<dependency>
  <groupId>com.duowan.android.netroid</groupId>
  <artifactId>netroid</artifactId>
  <version>(insert latest version)</version>
</dependency>

For Gradle projects use :

compile 'com.duowan.android.netroid:netroid:(insert latest version)'

At this point latest version is 1.2.1.

Documentation

For more detail about what Netroid can do, pay attention to the docs, that written by chinese.

Sample Application

To be straightforward, we build the sample apk, you can try all features without any source code.

License

Copyright 2013 Vince Styling

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.
Popular Http Projects
Popular Thread Projects
Popular Networking Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Java
Http
Thread
Imageloader