Ion Android getHeaders - android

How do I get a specific header using the Ion network library for Android?
This is what I'm trying:
...
.setCallback(new FutureCallback<Response<String>>() {
#Override
public void onCompleted(Exception e, Response<String> result) {
System.out.println("header: " + result.getHeaders().message("mykey"));
}
});

message(String) sets the HTTP response message. I should make that internal to avoid confusion.
Use
getHeaders().getHeaders().get(String)
It's a bit obtuse at the moment, will need to clean that API up in the next release.

Related

How to keep session alive? Android library Ion

I'm developing an android app that uses Ion library for requesting API data.
Here is how I'm requesting
void getData(final OnDbData listener) {
Ion.with(context)
.load(BASE_URL + url)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
#Override
public void onCompleted(Exception e, JsonObject jsonObject) {
if (e == null) {
listener.OnDbDataReceived(jsonObject, false);
} else {
Log.d("DBDATA-IonDB", e.getMessage() + "");
listener.OnDbDataReceived(jsonObject, true);
}
}
});
}
I'm successfully login in to my application but when I send request for other data Ion library is opening new connection and API is returning UNAUTHORIZED error. From the server side the session time out is set to 2 hours. One more thing that is confusing me is that when I use my local server (API in my computer) it is working correctly but when I connect to remote server It is being disconnected. If you know how to handle this please help!

Callback call with Ion on Intent Service(android)

In my application I want to send my recordings to the web site on backgroud. I've researched and I reached the conclusion that I should use and IntentService.
But this leads me to a problem, i cannot reach the callback of Ion inside the IntentService.
The callback is important because I want to delete the file after finishing the upload.
How can I make this?
This is my code:
Ion.with(this)
.load(ip_address)
.setMultipartParameter("key", key)
.setMultipartFile("audio_file", array_mp3[idx])
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
#Override
public void onCompleted(Exception e, JsonObject result) {
Log.d("BackS", "wifiteste - chega aqui ");
array_mp3[idx].delete();
}
});
I never reach that Log which means that i never delete the file.
Thanks in advance.

Android koush ion library catch 401 error

I'm using Koush Ion on Android to handle net operations.
I'd like to add a common handler to handle 401 unauthorized error.
How i can do it?
thank you
Ion.with(this)
.load("http://google.com")
.asString()
.withResponse()
.setCallback(new FutureCallback<Response<String>>() {
#Override
public void onCompleted(Exception e, Response<String> result) {
if(result.getHeaders().code()){
// ............
}
}
});
goodluck!

How to make a synchronous GET request with volley library? And how to parse it afterwards?

I've seen answer to both of these questions, however, when I tried to put them together, I couldn't make it work. The problem itself is pretty simple: I want to get a string from one site and use it in a post request. That means I can only make the post request after I've finished parsing the GET request. The main ideas I'm using are these ones:
How to return response header field to main method using Google Volley for HTTP GET request in Android / Java?
Can I do a synchronous request with volley?
However the synchronous request is blocked and doesn't go on, and the first one is Async.
I believe this to be a simple thing to do, but still, I haven't be able to do it...
Thanks for any help!
Why not do something like this:
// send first request
requestQueue.add(firstRequest, null, new Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
// ** code to parse response **
// send second request
requestQueue.add(secondRequest, null, new Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
// ** code to parse response **
}
}, new ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
// ** code to handle errors **
}
}));
}
}, new ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
// ** code to handle errors **
}
}));

Push Messages using REST api in android

I am developing an Android app using Parse.com website. In which whatever user sends data that must be received by receiver, but here I have to use REST api. I succeeded to send data to Parse website but now I have to Push that data with the help of REST api only. I am confused with REST api. Help to solve it.
You can use a library for that. I would suggest this one https://github.com/kodart/Httpzoid
It has clean API and type-safe data.
Here is a simple usage example
Http http = HttpFactory.create(context);
http.post("http://example.com/users")
.data(new User("John"))
.execute();
Or more complex with callbacks
Http http = HttpFactory.create(context);
http.post("http://example.com/users")
.data(new User("John"))
.handler(new ResponseHandler<Void>() {
#Override
public void success(Void ignore, HttpResponse response) {
}
#Override
public void error(String message, HttpResponse response) {
}
#Override
public void failure(NetworkError error) {
}
#Override
public void complete() {
}
}).execute();
It is fresh new, but looks very promising.

Categories

Resources