0
我必須作出一個呼叫HTTP GET
當用戶登錄在某個URL,並查看GET
在WebView
的HTTP GET調用的API和觀看關於web視圖
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();
}
}
但是我在視圖上看不到任何東西。我發現上面的代碼here.
仍然沒有解決。 –