[英]url will not load in webview
I have an application that has a fragment that contains a web view.我有一个包含 Web 视图的片段的应用程序。 The web view functions properly when I try other URLs however when I attempt to use "http://peekatu.com/scraper/onair.php" it will not load in the web view.
当我尝试其他 URL 时,Web 视图正常运行,但是当我尝试使用“http://peekatu.com/scraper/onair.php”时,它不会加载到 Web 视图中。 I have no idea as to why it won't load.
我不知道为什么它不会加载。 Help is appreciated.
帮助表示赞赏。 Thank you.
谢谢你。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v= inflater.inflate(R.layout.fragment_listen_live, container, false);
btn = (Button) v.findViewById(R.id.button1);
btn.setOnClickListener(pausePlay);
web_v= (WebView) v.findViewById(R.id.webView);
WebSettings web_sett=web_v.getSettings();
web_sett.setJavaScriptEnabled(true);
//web_v.setWebViewClient(new MyWebClient());
web_v.setWebChromeClient(new WebChromeClient());
web_v.loadUrl("http://peekatu.com/scraper/onair.php");
MainActivity m = (MainActivity) getActivity();
m.changeMenu("homePage");
this.getSherlockActivity().getSupportActionBar().setTitle("Power 92 Chicago");
this.getSherlockActivity().getSupportActionBar()
.setSubtitle("#1 in the Streets!");
return v;
}
private class MyWebClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
web_v.loadUrl(url);
return true;
}
}
onair.php onair.php
<?php
set_time_limit(0);
ignore_user_abort(FALSE);
error_reporting(E_ERROR);
ini_set('display_errors', 'on');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.power92chicago.com/');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
if (isset($_SERVER['HTTP_USER_AGENT'])) {
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
}
$dom = new DOMDocument();
$dom->loadHTML(curl_exec($ch));
$xpath = new DOMXPath($dom);
$node = $xpath->query("//td[contains(concat(' ', normalize-space(@class), ' '), ' TimeFeatureHorizontalTd ')]")->item(0);
echo get_inner_html($node);
function get_inner_html($node) {
$innerHTML= '';
$children = $node->childNodes;
foreach ($children as $child) {
$innerHTML .= $child->ownerDocument->saveXML( $child );
}
return $innerHTML;
}
?>
Before you call loadUrl
, add this line:在调用
loadUrl
之前,添加以下行:
web_v.setWebChromeClient(new WebChromeClient());
Also, I don't know why you define a WebViewClient
that overrides shouldOverrideUrlLoading
and then calls loadUrl
yourself - just remove that.另外,我不知道你为什么定义一个覆盖
shouldOverrideUrlLoading
的WebViewClient
然后自己调用loadUrl
- 只需删除它。
Testing with the mobile browser the webpage doesn't load so the problem is definetly not in your android code, the problem is on the php code.使用移动浏览器测试网页无法加载,因此问题肯定不在您的 android 代码中,问题出在 php 代码上。
Can you share the code to generate that web?你能分享生成那个网站的代码吗?
Also if what you are trying to do is show information in your app you might need to think a different approach, if you want to display a list of data in your app, you might want to use a listView and getting the data from a JSON REST Api rather than displaying that list in a php website此外,如果您想要做的是在您的应用程序中显示信息,您可能需要考虑不同的方法,如果您想在您的应用程序中显示数据列表,您可能需要使用 listView 并从 JSON 中获取数据REST Api 而不是在 php 网站中显示该列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.