0
I’m creating an app that it accesses a URL page, query some data, and returns the result in a Alert dialog, however in the web code, made in PHP, I need to put some " n" to format the data, and everything that there is before the " n" Android does not interpret, ie if the result has:
Answer, "n", answer2, Android can only read the "answer2", did anyone have the same problem? Below follows my Android code that performs the query and generates the answer.
URLConnection con = url.openConnection();
con.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
writer.write("nome="+nomeProduto+"&aliquota="+aliquota+(laboratorio != null ? "&laboratorio="+laboratorio : ""));
writer.flush();
String line;
StringBuffer result=new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
while ((line = reader.readLine()) != null) {
alertDialog.setMessage(line);
alertDialog.setButton("Voltar",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}});
alertDialog.show();
}
writer.close();
reader.close();
The problem is you’re making one
readLine()
which reads basically until you find ' n'.– Jorge B.