在我的JsonParsing中,我从这个json获得了url。我需要在webview中显示该Url链接。 我该怎么做?
代码就在这里:
TextView tv = (TextView)findViewById(R.id.textView1);
Bundle bundle = new Bundle();
bundle = getIntent().getExtras();
String id = bundle .getString("id");
String firstName = bundle.getString("firstName");
String lastName = bundle.getString("lastName");
String headline = bundle.getString("headline");
String pictureUrl = bundle.getString("pictureUrl");
String url = bundle.getString("url");
Log.v("LV","id :"+id+"\n"+"firstname :"+firstName+"\n"+"lastname :"+lastName+"\n"+"headline :"+headline+"\n"+"pictureUrl :"+pictureUrl+"\n"+"siteStandardProfileRequest"+url);
tv.setText("id :"+id+"\n"+"firstname :"+firstName+"\n"+"lastname :"+lastName+"\n"+"headline :"+headline+"\n"+"pictureUrl :"+pictureUrl+"\n"+"Profile URL :"+url);
答案 0 :(得分:4)
因为你要求在webview中打开url所以你必须在你的项目中使用一个webview并且这样做
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);
// you need to setWebViewClient for forcefully open in your webview
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
和其他方式(这将在网络浏览器中打开)
Intent browserIntent = new Intent(Intent.ACTION_VIEW,uri.parse(url));
startActivity(browserIntent);
答案 1 :(得分:2)
使用此代码:
webView = (WebView) findViewById(R.id.webView1);
progressDialog = ProgressDialog.show(MainActivity.this, "", "Loading...",true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.getSettings().setAllowFileAccess(true);
webView.loadUrl("http://example.com/shidhin/test.html"); // Here You can put your Url
webView.setWebChromeClient(new WebChromeClient() {
});
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
public void onPageFinished(WebView view, String url) {
progressDialog.dismiss();
//Toast.makeText(context, "Page Load Finished", Toast.LENGTH_SHORT).show();
}
});