Skip to content

Instantly share code, notes, and snippets.

@yaronv
Last active August 29, 2015 14:24
Show Gist options
  • Save yaronv/9a12f3fed8ba422bd9ab to your computer and use it in GitHub Desktop.
Save yaronv/9a12f3fed8ba422bd9ab to your computer and use it in GitHub Desktop.
package yv.recipe.tasks;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.extensions.android.json.AndroidJsonFactory;
import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
import com.google.api.client.googleapis.services.GoogleClientRequestInitializer;
import com.yv.recipe.backend.process.Process;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import yv.recipe.Properties.Properties;
import yv.recipe.Properties.PropertyMapper;
public class ProcessImageAsyncTask extends AsyncTask<Void, Void, String> {
private Process processService = null;
private Context context;
public ProcessImageAsyncTask(Context context) {
this.context = context;
}
@Override
protected String doInBackground(Void... params) {
String msg = "";
try {
Process.Builder builder = new Process.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)
// Need setRootUrl and setGoogleClientRequestInitializer only for local testing,
// otherwise they can be skipped
.setRootUrl("http://10.0.2.2:8080/_ah/api/")
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
processService = builder.build();
return processService.greet().execute().toString();
} catch (Exception ex) {
ex.printStackTrace();
msg = "Error: " + ex.getMessage();
}
return msg;
}
@Override
protected void onPostExecute(String msg) {
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
Logger.getLogger("PROCESS").log(Level.INFO, msg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment