【发布时间】:2015-04-24 07:10:16
【问题描述】:
我有一些博客的 JSON 内容,我在 WebView 中使用 loadDataWithBaseURL 显示这些内容。该博客的许多文章都嵌入了 youtube/vimeo 视频。
目前,所有视频都在 webview 本身内播放。
我想要实现的是,当用户点击播放视频时,他应该会弹出“使用浏览器或 YouTube 应用程序完成操作”。简而言之,我不希望视频在应用的 webview 中播放。
我发现每个人都试图避免这个弹出窗口的问题。不知道为什么我没有得到它。
这是我的代码
public class DetailFragment extends Fragment {
String strTitle = null;
String strURL = null;
String strContent = null;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
AdView mAdView = (AdView) getView().findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.detail_fragment, container, false);
strTitle = getArguments().getString("title");
strURL = getArguments().getString("url");
strContent = getArguments().getString("content");
String contToDisplay = "<html><head><meta http-equiv='Content-Type' content='text/html' charset='UTF-8' /></head><body><style type='text/css'> img{width:80%;} .wp-image-42223{display:none;}</style>" + strContent+"</body></html>";
TextView title = (TextView) view.findViewById(R.id.title);
WebView desc = (WebView) view.findViewById(R.id.desc);
WebSettings ws = desc.getSettings();
ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
ws.setJavaScriptEnabled(true);
ws.setLoadWithOverviewMode(true);
ws.setUseWideViewPort(true);
ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
ws.setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
title.setText(strTitle);
// desc.loadData(contToDisplay, "text/html; charset=UTF-8", null);
desc.loadDataWithBaseURL("about:blank",strContent,"text/html", "UTF-8", null);
return view;
}
}
任何能让视频在浏览器或 YouTube 应用中加载的解决方案都会有所帮助。
注意
我在 webview 中显示的内容是 HTML 格式,其中 iframe 作为元素之一。这是示例数据:
"<p>Some text</p>
<p><iframe src=\"https://www.youtube.com/embed/q7uBAtaK15I\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"></iframe> </p>
<p>some more text</p>
整个内容都显示在 webview 中。我想要实现的是当有人点击iframe时,应该提示他complete action using,即不允许该人在webview中播放视频
【问题讨论】:
标签: android json iframe webview