Aparece o circulo do Toast mas sem nenhuma mensagem. Havia feito o teste antes e estava enviando os dados como o nome do aluno e a nota. Não achei o que pode estar errado.
public class WebClient {
public String post(String json) {
try {
URL url = new URL("https://www.caelum.com.br/mobile");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Content-type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
connection.setDoInput(true);
PrintStream outPut = new PrintStream(connection.getOutputStream());
outPut.println(json);
connection.connect();
Scanner scanner = new Scanner(connection.getInputStream());
String responseServer = scanner.next();
return responseServer;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
public class SendStudentTask extends AsyncTask<Void, Void, String> {
private Context context;
private ProgressDialog dialog;
public SendStudentTask(Context context) {
this.context = context;
}
@Override
protected String doInBackground(Void... params) {
StudentDao dao = new StudentDao(context);
List<Student> students = dao.searchStudents();
dao.close();
StudentConvert convert = new StudentConvert();
String json = convert.convertToJSON(students);
WebClient client = new WebClient();
String averegeGrade = client.post(json);
return averegeGrade;
}
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(context,
"Aguarde", "Enviando Aluno", true, true);
}
@Override
protected void onPostExecute(String averageGrade) {
dialog.dismiss();
Toast.makeText(context, averageGrade, Toast.LENGTH_LONG).show();
}
}
`