I am creating an app for electricity recharge payment. i want the app to work like this., a customer enters his/her meter number together with the amount to be paid. After clicking the submit button,this info has to be sent to the Service Provider using a POST Request via the OKHTTP3 protocol. I wrote the code below and its showing nothing when i click the Submit Button. Please help.
package googleplayservices.samples.android.com.whitney.shumba;
import android.content.Intent;
import android.renderscript.RenderScript;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class Zesa extends AppCompatActivity {
private TextInputEditText txtinputmeter,txtinputamount;
private Button submit;
private TextView json;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zesa);
json = (TextView) findViewById(R.id.jsonTV);
txtinputmeter = (TextInputEditText) findViewById(R.id.txt_input_meter);
txtinputamount = (TextInputEditText)
findViewById(R.id.txt_input_amount);
submit = (Button) findViewById(R.id.submitButton);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Okhttp3 client network request
OkHttpClient client = new OkHttpClient();
String url = "https://www.shumbapay.com";
Request request = new Request.Builder()
.url(url)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws
IOException {
if(response.isSuccessful()){
final String myResponse = response.body().string();
Zesa.this.runOnUiThread(new Runnable() {
@Override
public void run() {
json.setText(myResponse);
}
});
}
}
});
Submit();
}
private void Submit() {
startActivity(new Intent(Zesa.this, Payzesa.class));
}
});
}
}