volley

2022. 5. 3. 15:19개발자료/Android


반응형

       

최신버전 확인

https://google.github.io/volley/

 

Volley overview

Volley overview Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. Volley is available on GitHub. Volley offers the following benefits: Automatic scheduling of network requests. Multiple concurrent network

google.github.io

 

build.gradle 항목추가
dependencies {
    ...
    implementation 'com.android.volley:volley:1.2.1'
}

 

Simple Request
final TextView textView = (TextView) findViewById(R.id.text);
// ...

// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url = "https://www.google.com";

// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        // Display the first 500 characters of the response string.
        textView.setText("Response is: " + response.substring(0,500));
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        textView.setText("That didn't work!");
    }
});

// Add the request to the RequestQueue.
queue.add(stringRequest);
타임아웃 설정
JsonObjectRequest jsonRequest = new JsonObjectRequest(Method.GET, url, null,
	new Response.Listener<JSONObject>() {
		@Override
		public void onResponse(JSONObject response) {
			// Response
		}
	}, new Response.ErrorListener() {
		@Override
		public void onErrorResponse(VolleyError error) {
			// Error
		}
	}
);
jsonRequest.setRetryPolicy(new DefaultRetryPolicy(
	60*1000, // 60Sec
	DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
	DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
);

 

 

 

반응형

'개발자료 > Android' 카테고리의 다른 글

[SQLiteDatabase] WHERE절 LIKE에 WILDCARD 사용하기  (0) 2022.06.21
특정 시간후에 코드 실행하기  (0) 2022.05.03
Android NFC Mode  (0) 2022.01.04
escape  (0) 2021.09.29
Android 개발 관련 정보  (0) 2020.12.18