Skip to content

Instantly share code, notes, and snippets.

@AndreiD
Last active September 30, 2018 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreiD/20c371f463058a4fd0cc1e2d07347b13 to your computer and use it in GitHub Desktop.
Save AndreiD/20c371f463058a4fd0cc1e2d07347b13 to your computer and use it in GitHub Desktop.
dsfa
package com.mex.integrationapp;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import java.io.IOException;
import gotomobile.Gotomobile;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new RunServerTask().execute();
new CountDownTimer(1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://localhost:8080/welcome?firstname=Me&lastname=You")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Response response) throws IOException {
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
Log.d("> GOT >", response.body().string());
}
});
}
}.start();
}
static class RunServerTask extends android.os.AsyncTask {
@Override
protected Object doInBackground(Object[] objects) {
Gotomobile.runServer();
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment