I have to make an HTTP GET
call to a certain URL when the user is logged in, and view the response of GET
in a WebView
PlayBack.java (WebView):
public class PlayBack extends Activity {
WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.play_back);
wv = new WebView(this);
wv.setWebViewClient(new CustomWebView());
}
private class CustomWebView extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent intent = getIntent();
String id = intent.getStringExtra("pid");
String playUrl = "certain url"+id;
String htmlCon = "";
HttpGet httpGet = new HttpGet(playUrl);
try{
HttpResponse httpResponse = MainActivity.httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream inputStream = httpEntity.getContent();
htmlCon = convertToString(inputStream);
wv.loadData(htmlCon, "text/html", "utf-8");
}catch(Exception e) {
}
return false;
}
}
public String convertToString(InputStream inputStream){
StringBuffer string = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line="";
try {
while ((line = reader.readLine()) != null) {
string.append(line + "\n");
}
} catch (Exception e) {}
return string.toString();
}
}
But I don't see anything on the view. I found the above code here.