【发布时间】:2013-09-05 08:09:17
【问题描述】:
这两天我无法直接在移动模式下启动我的 webview。当我第一次打开应用程序时,webview 会显示桌面。我的代码
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // Request progress circle
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
WebSettings websettings = webview.getSettings();
websettings.setJavaScriptEnabled(true);
webview.getSettings().setUserAgentString("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");
setProgressBarIndeterminateVisibility(true); // Show progress circle
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
setProgressBarIndeterminateVisibility(false); // Hide progress circle when page loaded
activity.setTitle("Title");
}
});
if (savedInstanceState == null)
{
webview.loadUrl("http://forum.ubuntu-it.org/");
}
}
即使我更改了用户代理也不起作用!我尝试了各种方式。我希望得到某人的帮助,谢谢。
【问题讨论】:
-
论坛有移动视图替代方案还是有移动视图?
-
是的,当我用手机在页面底部打开网站时,有一个“链接”可以将版本更改为移动视图。也许问题是这样的。也许网站无法自动识别设备,但您必须手动更改版本..奇怪..
-
您在选择移动视图后是否注意到任何 url 变化?
-
编辑:我尝试使用股票浏览器输入。链接显示:
http://forum.ubuntu-it.org/?mobile=off。这意味着它识别设备(查询字符串显示**mobile**=off)但不会自动启动..我认为问题出在网站上 -
我尝试将 url 更改为
http://forum.ubuntu-it.org/?mobile=on并且移动视图在 chrome 中工作!!,所以我建议您尝试将 url 更改为上述。
标签: java android android-webview user-agent mobile-website