力的WebView网站的移动版本 [英] Force mobile version of website for WebView
问题描述
我加载URL到网页视图来显示它为我的应用程序。我遇到的问题是,这并不总是该网站承认,我是一个电话(为什么这么过?)。究竟如何强制web视图发送到我手机网站?目前我正在做这样的
I'm loading an URL into a webview to display it into my app. The problem I'm encountering is, that not always the site recognizes that I'm a phone (why so ever?). How exactly do I force the webview to send to the site that I'm a mobile phone? Currently I'm doing it like that
webview.getSettings()setUserAgentString(Mozilla的/ 5.0(iPhone; U; CPU喜欢Mac OS X; EN)为AppleWebKit / 420 +(KHTML,例如Gecko)版本/ 3.0移动/ 1A543a Safari浏览器/ 419.3);
但是,这并不工作?因为我没有使用iPhone将无法工作?我不认为这是因为它只是设置用户代理的原因...
But that doesn't work? Won't it work because I'm not using an iPhone? I don't think that this is the reason since it's just setting the user Agent...
这是有关code(在irelevant code只包含如意图得到一个URL和格式化字符串数据)
This is the relevant code (the irelevant code just contains data such as getting an url from an intent and formatting a string )
//package
//imports
public class WebViewing extends Activity {
private WebView webview;
private ProgressDialog dialog;
//init strings
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webviewer);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
//init variables
//get intent data and format string
this.webview = (WebView) findViewById(R.id.webView1);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
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");
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
if (dialog.isShowing()) {
dialog.dismiss();
}
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
dialog.setMessage("Website wird geladen...\nDies ist abh\u00E4ngig von deiner Internet-Verbindung.");
dialog.setCanceledOnTouchOutside(false);
dialog.show();
webview.loadUrl(sourceURL);
setTitle("Platz: " + plusRank + " - " + realDate);
}
//onCreateOptionsMenu method
//onOptionsItemSelected method
}
我也尝试了这个字符串为用户代办
I also tried out this string for the user agent
的Mozilla / 5.0(Linux的; U; Android 2.2的; EN-US; Nexus One的编译/ FRF91)为AppleWebKit / 533.1(KHTML,例如Gecko)版本/ 4.0移动版Safari / 533.1
推荐答案
尽量把这些如下: -
try to put these following lines :-
webview.getSettings().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");
这篇关于力的WebView网站的移动版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!