I’ve tried this example and it works fine with the example URL (http://search.yahoo.com/search), but when I do it for “http://www.ilias.de/docu/login.php?target=&client_id=docu”, I can’t see the response in webview correctly. I mean, all text is visible, but the images are not. And links don’t work.
How do I fix this problem?
public class ilias extends Activity {
WebView webView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView)findViewById(R.id.webview);
BufferedReader bufferedReader = null;
HttpClient httpClient = new DefaultHttpClient();
HttpPost request = new HttpPost("http://www.ilias.de/docu/login.php?client_id=docu");
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", "stacked")); //This username
postParameters.add(new BasicNameValuePair("password", "overflow")); //works.
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParameters);
request.setEntity(entity);
HttpResponse response= httpClient.execute(request);
bufferedReader = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer stringBuffer = new StringBuffer("");
String line = "";
String LineSeparator = System.getProperty("line.separator");
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line + LineSeparator);
}
bufferedReader.close();
Toast.makeText(ilias.this,
"Finished",
Toast.LENGTH_LONG).show();
String webData = stringBuffer.toString();
webData = webData.replace("#", "%23");
webData = webData.replace("%", "%25");
webData = webData.replace("\\", "%27");
webData = webData.replace("?", "%3f");
webView.loadData(webData,
"text/html",
"UTF-8");
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ilias.this,
e.toString(),
Toast.LENGTH_LONG).show();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ilias.this,
e.toString(),
Toast.LENGTH_LONG).show();
}
finally{
if (bufferedReader != null){
try {
bufferedReader.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
This is what I’ve got: http://img64.imageshack.us/img64/4913/deviceyl.png, and this is what I want: http://img200.imageshack.us/img200/8591/device1g.png
I think you’ve got to use
loadDataWithBaseURl("http://www.ilias.de/docu/",webData,"text/html","UTF-8","about:blank");instead of
webView.loadData(webData, "text/html", "UTF-8");The “simple” loadData method does not load content from the network, according to the reference.
@@@@@@@ EDIT @@@@@@@
In order to see the page just like in the native browser, first remove these lines:
This is because, either I’m not understanding the API documentation or the loadDataWithBaseUrl does’t not decode the characters back.
And play around with the zoom level (you can do that programmatically)
Regards
