我目前正在开发一款基于网站的Android应用程序。已经存在iOS应用程序,因此我必须遵守某些代码以保持统一性。
几乎所有的事情都已完成,但是我刚刚发现了一个有趣的问题:当使用Webview(我无法控制显示的页面)查看带有iframe视频(Youtube,Dailymotion)的页面时,即使我按下播放器的按钮,视频也不会全屏。
我已经尝试了这里找到的几乎所有方法,但这些方法只适用于我知道需要显示哪些页面的应用程序。
这是应用程序中webActivity部分的代码:
public class WebActivity extends Activity {
String targetURL = "";
String title = "";
WebView wv;
@Override
public void onResume() { super.onResume(); CookieSyncManager.getInstance().startSync(); }
@Override
public void onPause() { super.onPause(); CookieSyncManager.getInstance().stopSync(); }
/** Called when the activity is first created. */
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
//getWindow().requestFeature(Window.FEATURE_NO_TITLE);
CookieSyncManager.createInstance(getApplicationContext());
CookieSyncManager.getInstance().startSync();
CookieManager.getInstance().setAcceptCookie(true);
/**
* TODO: WebView Cookie management.
* Right now, a cookie is hardcoded here into the WebView instead of getting it from the API called by HttpClient when retrieving the JSON.
* Need to make things cleaner.
*/
CookieManager.getInstance().setCookie("http://www.blabla.fr/mobile/","gbapi=1; Domain=.www.blabla.fr");
/**
* Get parameters
*/
Bundle b = getIntent().getExtras();
if(b != null)
{
targetURL = b.getString("url");
title = b.getString("title");
}
setTitle(title);
setContentView(R.layout.activity_webview);
wv = (WebView) findViewById(R.id.webview);
WebSettings wvSettings = wv.getSettings();
// WebView options
wvSettings.setDefaultTextEncodingName("utf-8");
wvSettings.setJavaScriptEnabled(true);
wvSettings.setPluginState(PluginState.ON);
wvSettings.setJavaScriptCanOpenWindowsAutomatically(true);
wvSettings.setBuiltInZoomControls(true);
final Activity activity = this;
wv.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setProgress(progress * 100);
}
});
wv.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh snap! " + description, Toast.LENGTH_SHORT).show();
}
});
wv.loadUrl(targetURL);
}
}
感谢任何帮助。