我正在尝试将 twitter 小部件嵌入到 webview 中,但感觉 JS 代码没有执行。显示的只是“@xxxxxx 的 Twitter”
WebView webView = new WebView(getActivity());
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getActivity(), "Oh no! " + description, Toast.LENGTH_LONG).show();
}
});
String summary = "<a class=\"twitter-timeline\" href=\"https://twitter.com/"+getArguments().getString("handle")+"\" data-widget-id=\""+getArguments().getString("widgetId")+"\">Tweets by @"+getArguments().getString("handle")+"</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.src=p+\"://platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");</script>";
webView.loadData(summary, "text/html", null);
return webView;
我的应用程序确实具有 Internet 访问权限