I have an android application that has several buttons on different screens, I should attach the clicked buttons and send to MySQL. li about webservices ( link ) and you need an AsyncTask to make that connection.
banco_mysql.java
package com.example.deadsec.gerflores_beta;
import android.os.AsyncTask;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* Created by DEDSEC on 24/04/2017.
*/
public class banco_mysql extends AsyncTask<Void, Void, String> {
@Override
public String doInBackground(Void... params) {
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
try {
URL url = new URL("http://IP:PORTA/BANCO/USUARIO/SENHA");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
reader = new BufferedReader(new InputStreamReader(inputStream));
String linha;
StringBuffer buffer = new StringBuffer();
while((linha = reader.readLine()) != null) {
buffer.append(linha);
buffer.append("\n");
}
return buffer.toString();
} catch (Exception e) {
e.printStackTrace();
if (urlConnection != null) {
urlConnection.disconnect();
}
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
return null;
}
@Override
protected void onPostExecute(String dados) {
// Faça alguma coisa com os dados
}
}
I do not quite understand how you are connecting to the bank, how to implement this in Activity_final
to gather the data ( clicked ) and how to send it to the bank.
Please help me.