Android does not interpret a webpage's "\ n" command

0

I am creating an app that it accesses a URL page, it queries some data, and returns the result in an alert dialog , but in the web code, made in PHP, I need to put some \ n "to format the data, and everything there is before \ n" Android does not interpret, ie if the result has:

Answer, "\ n", answer2, Android can only read "answer2", has anyone had the same problem? Below is 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();
    
asked by anonymous 28.01.2015 / 18:32

1 answer

1

Do this:

String result="";
while((line = br.readLine())!=null){
     result += line;
}

alertDialog.setMessage(result);
alertDialog.setButton("Voltar",new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int id) {
            dialog.cancel();
        }});
alertDialog.show();

This will read all the lines.

    
28.01.2015 / 19:33