Giter Site home page Giter Site logo

haoht / androidnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xuningjack/androidnet

1.0 1.0 0.0 35.87 MB

Java & Android Network Module(JAVA网络、Android网络操作:包括网络请求、WebView相关、常用第三方框架OkHttp&Volley)

Java 98.51% HTML 1.49%

androidnet's Introduction

AndroidNet

本项目涵盖了JAVA网络、Android网络操作(网络请求、WebView相关、常用第三方框架OkHttp&Volley)

1 JavaSocketDemo

本demo演示了InetAddress、URL的用法,模拟单客户端、多客户端的socket和udp的通信。

2 AndroidHttpDemo

本demo演示了使用HttpClient、HttpUrlConnection发送网络请求。

3 WebViewDemo

本demo演示了js与java原生代码的交互,还有通过html与java原生代码的交互。

4 VolleyDemo

本demo演示了volley的常规使用和封装。

Volley Module中封装了自定义的请求对象CustomVolleyRequest和请求回调VolleyListener。   使用其封装get请求如下: /**
* 使用自定义的get方式请求数据,二次封装
*/
private void volleyCustomGet(){
         CustomVolleyRequest.requestGet(url, "volleyCustomGet", new VolleyListener(this, VolleyListener.mListener, VolleyListener.mErrorListener) {
                  @Override
                  public void onMySuccess(String response) {
                           Toast.makeText(MainActivity.this, response, Toast.LENGTH_LONG).show();
                           Log.d(TAG, "volleyCustomGet-----" + response);
                  }
                  @Override
                  public void onMyError(VolleyError error) {
                           Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
                           Log.d(TAG, "volleyCustomGet error-----" + error.getMessage());
                  }
         });
}

5 OkHttpDemo

本demo演示了OkHttp的常规使用和封装。
demo中封装了CommonOkHttpClient里面有执行get、post、downloadFile的请求。

eg: CommonOkHttpClient.post(CommonRequest.createPostRequest(CITY_URL, params), new DisposeDataHandler(new DisposeDataListener() {
         @Override
         public void onSuccess(JSONObject responseObj) {
                  mResult.setText(responseObj.toString());
         }
         @Override
         public void onFail(Object responseObj) {
                  Log.e(TAG, "post onFail------" + responseObj.toString());
          }
}));

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.