我在WebView中有一个Twitter时间轴,显示效果非常好。我按照this post作为指导。目前我不想接受其他选项,如Twitter4J,虽然我很欣赏它是一个很好的选择。
我的问题是,除了向上和向下滚动之外,我无法点击任何链接,图片或以其他方式与时间轴交互。我收到以下错误。有什么方法吗?
05-29 19:09:10.887: I/chromium(13226): [INFO:CONSOLE(0)] "Refused to display 'https://mobile.twitter.com/XXXXXXXX/status/YYYYYYYYYY/photo/1' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.", source: https://twitter.com/XXXXXXXX/status/YYYYYYYYYY/photo/1 (0)
这是我的代码:
// Locate the WebView in fragment_twitter.xml
WebView tweetWebView = (WebView) V.findViewById(R.id.tweetWebView);
// Settings for the WebView
tweetWebView.setBackgroundColor(0);
tweetWebView.getSettings().setJavaScriptEnabled(true);
tweetWebView.getSettings().setDomStorageEnabled(true);
// Load the WebView with the imageURL
String timelineWidget = "<a class=\"twitter-timeline\" data-dnt=\"true\" href=\"https://twitter.com/XXXXXXXX\" data-widget-id=\"SECRETNUMBER\">Tweets by @XXXXXXXX</a><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.async=true;js.src=p+\"://platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");</script>";
tweetWebView.loadDataWithBaseURL("https://twitter.com", timelineWidget, "text/html", "UTF-8", null);
答案 0 :(得分:0)
My problem was same as above but the requirement was different, it was to open the link in the embedded webview and then open inside webview link in the native browser,
mWebView.setWebViewClient(new WebViewClient() {
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
Logger.logD(TAG, "URL = " + url);
if(mWebView.getVisibility() == View.VISIBLE && !HomeActivity.isPaused()) {
//Open url in native browser
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
return null;
}
return super.shouldInterceptRequest(view, url);
}
@Override
public void onPageFinished(WebView view, String url) {
//show embedded webview and hide the progress bar
mWebView.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
}
});
In Add boolean in Your activity
@Override
protected void onResume() {
super.onResume();
isPaused = false;
}
@Override
protected void onPause() {
super.onPause();
isPaused = true;
}
I hope few changes could lead you to the solution, Thanks