我目前正在开发基于网站的 Android 应用程序。iOS 应用程序已经存在,我必须尊重一些代码的统一性。
一切都差不多完成了,但我刚刚发现了一个有趣的问题:当对带有 iframe 视频(Youtube、Dailymotion)的页面使用 webview(我对显示的页面没有任何控制)时,它不会全屏显示,即使我按下播放器的按钮。
我已经尝试了在这里找到的几乎所有内容,但它仅指我知道您需要显示哪些页面的应用程序。
这是应用程序的 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);
}
}
谢谢你的帮助。