33 lines
871 B
Kotlin
33 lines
871 B
Kotlin
package com.example.testes
|
|
|
|
import android.content.Context
|
|
import com.android.volley.VolleyError
|
|
import com.android.volley.toolbox.JsonObjectRequest
|
|
import com.android.volley.toolbox.Volley
|
|
import org.json.JSONObject
|
|
|
|
class Request {
|
|
companion object {
|
|
fun getRequest(
|
|
context : Context,
|
|
url : String,
|
|
callback : (JSONObject) -> Unit
|
|
) {
|
|
|
|
//Create an instances of Volley's queue
|
|
val queue = Volley.newRequestQueue(context)
|
|
|
|
val errorCallback = fun (error: VolleyError) { error.printStackTrace() }
|
|
|
|
//String Request
|
|
val stringRequest = JsonObjectRequest(
|
|
url,
|
|
callback,
|
|
errorCallback
|
|
)
|
|
|
|
//Adding our request to the Volley's queue
|
|
queue.add(stringRequest)
|
|
}
|
|
}
|
|
} |