I am using following code to obtain some data from my website using android HttpURLConnection method and place it on webview textarea.But unfortunately the obtained data ignores all newlines and empty lines. Could an expert show me how i can keep the empty lines and new lines on my final result ?Thanks in advance.
test.Data.php data:
helloWorld1
next2
next3
output:
helloWorld1next2next3
expected output:
helloWorld1
next2
next3
Android code:
public String sendGetRequest() {
try {
StrictMode.setThreadPolicy(new Builder().permitAll().build());
HttpURLConnection myURLConnection = (HttpURLConnection) new URL("http://mywebsite.com/testData.php").openConnection();
myURLConnection.setReadTimeout(60000);
myURLConnection.setConnectTimeout(60000);
myURLConnection.setRequestMethod("GET");
myURLConnection.setUseCaches(false);
myURLConnection.setDoInput(true);
myURLConnection.setDoOutput(true);
myURLConnection.setRequestProperty("Content-Type", "text");
myURLConnection.setRequestProperty("User-Agent", "Dalvik/2.1.0 (Linux; U; Android 6.0;");
OutputStream os = myURLConnection.getOutputStream();
os.close();
myURLConnection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
sb.append(line);
}
in.close();
// Update your UI
mWebView.loadUrl("javascript:Parseit('" + sb.toString() + "');");
} catch (Exception e) {
}
return null;
}
javascript on webview:
function Parseit(data)
{
var myTextArea = document.getElementById('area1');
myTextArea.innerHTML += data+"\n";
};
next2
next3. I have to mention that i used different approach by adding
manually to my sever data(testData.php) to see if that makes a difference but still all in one line!(if i don't put those
and only type the data on different lines then when i type the url on browser all the data shows in one line!) .So sever data with or without
produces all data on one line inside webview textarea! – user1788736 Nov 22 '17 at 04:44
in your server – diegoveloper Nov 22 '17 at 04:45