Callback call with Ion on Intent Service(android) - 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.

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!

Connecting to Azure Blob Storage from Android

I'm trying to make a mobile app that, eventually in one of its activities will connect to a Blob storage in Android to transfer a collection of images.
But I couldnt even get there, since one of the requirements is making that connection to be safe, since the client could be anyone from his mobile phone, so my first step here is requesting a SAS token prior to start any transaction.
So this is basically two steps that I'm following,
1 -> Implemented an Azure Function inside my App Service that returns a SAS token (I got that function from here: Sas Token Function
)
2 -> Trying to call that function from my Android Code and get my SAS token.
Looks really easy and I'm sure it is, the function in the link explains the required http body to ask for concrete access, and I think is there where I'm failing, below is my code to call the function:
private void getStringFromAzure() throws MalformedURLException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("container", "uploadedimages");
jsonObject.addProperty("permissions", "Write, Create");
// Create the MobileService Client object and set your backend URL
String yourURL = "https://mydirectory.azurewebsites.net/";
MobileServiceClient mClient = new MobileServiceClient(yourURL, this);
// Your query pointing to yourURL/api/values
ListenableFuture<JsonElement> query = mClient.invokeApi("GetSasToken-Net", jsonObject, "POST", null);
// Callback method
Futures.addCallback(query, new FutureCallback<JsonElement>() {
#Override
public void onSuccess(JsonElement jsonElement) {
final String result = jsonElement.toString();
// Since you are on a async task, you need to show the result on the UI thread
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(mContext, result, Toast.LENGTH_LONG).show();
}
});
}
#Override
public void onFailure(Throwable throwable) {
Log.d(TAG, "onFailure: " + throwable.getMessage());
}
});
}
The code is failing in "InvokeApi" line function, where throws an exception before even warning me that is going to connect to Internet from mobile.
Another thing that I think could be wrong is that, nowhere in the Azure Get Sas Token Function is specifying my account credentials ( I didnt developed that function, but should work fine as it is, it anyways doesnt let you change anything, imported via GitHub )
I have really small base/background in this kind of things and Im sure I'm missing something (or "lots" of somethings), but I really appreciate a hand, this is driving me crazy.
PD. Internet permissions already given in manifest.
Thank you all in advance, first post in StackOverflow after following for many years!

Ion Android getHeaders

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.

Android : How to use Cache in ion library?

In my case, I want to load data from Cache. If there is cache load from cache else load from network. How can I use caching in Ion?
private void loadION() {
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("loading");
progressDialog.show();
Ion.with(getApplicationContext()).load(url)
.setBodyParameter("tag", "annual_schedule").asString()
.setCallback(new FutureCallback<String>() {
#Override
public void onCompleted(Exception e, String str) {
Message.Toast(getApplicationContext(), str);
progressDialog.dismiss();
}
});
}
Ion will automatically cache GET requests. This is a POST request, and can not be cached by the library.
Furthermore, cached requests can't be used right away, since disk I/O is still treated as a blocking call. It will still be an asynchronous request.

Pinterest Android SDK / Callback after successful pin?

Fellow SO members,
I am trying to figure out how to get a callback from the Android Pinterest SDK, after a "pin it" event has successfully completed. I have implemented the SDK as follows:
PinIt pinIt = new PinIt();
pinIt.setUrl(socialContent.getLink());
pinIt.setImageUrl(socialContent.getPicture());
pinIt.setDescription(socialContent.getMessage());
pinIt.setListener(new PinItListener() {
#Override
public void onStart() {
super.onStart();
}
#Override
public void onComplete(boolean completed) {
super.onComplete(completed);
if (completed) {
handle Pin It form displayed=true event
}
}
#Override
public void onException(Exception e) {
super.onException(e);
exception handling code...
}
});
pinIt.doPinIt(getActivity());
Per the documentation, onComplete(true) gets called as soon as the Pin It form comes up. What I'm looking for is a way to get a callback when the "Pin It" event is successfully completed. So far, I have found now way to do this.
My iOS co-worker found that there was a way to register an app URI ("yourapp://blah") as a form of callback. I have found no such way to do this in the Android Pinterest SDK.
Does anyone know how to receive an event after the "Pin It" event is successfully completed?

Categories

Resources