0
I have an android application that has several buttons on different screens, I must join the buttons clicked and send to Mysql. I read about webservices (http://www.androidpro.com.br/webservice/) 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 don’t quite understand how you’re connecting with the bank, how to implement this in the Activity_final
to gather the data (clicked buttons) and how to send to the bank.
please help me.
What is the question regarding the connection to the database? Note that for the URL class you pass as parameter the path, in this case, a remote database.
– naydsonmariosa
@naydsonmariosa I could not make it work, I do not know if that connection is certain but I have no idea how to gather the data and send to the web service
– Garcez