I'm having a problem with my android webview app. The app run normal in some devices but it won't load mobile version when I use in Sony Acro S, it's always load web version. For first time, I think maybe it is my android version (4.1.2) but I tried in different device with same os version (4.1.2) and the result is the device load mobile version not web version. Here's my code,
我的android webview应用程序出了问题。该应用程序在某些设备上运行正常但在我使用Sony Acro S时它不会加载移动版本,它总是加载网络版本。第一次,我想也许这是我的Android版本(4.1.2),但我尝试在不同的设备与相同的操作系统版本(4.1.2),结果是设备加载移动版本而不是网络版本。这是我的代码,
public class MainActivity extends Activity
{ private WebView browser;
{private WebView browser;
private ProgressBar progressBar;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
browser = (WebView) findViewById(R.id.webkit);
WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
// set javascript and zoom and some other settings
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setBuiltInZoomControls(false);
browser.getSettings().setGeolocationEnabled(true);
browser.getSettings().setAppCacheEnabled(true);
browser.getSettings().setDatabaseEnabled(true);
browser.getSettings().setDomStorageEnabled(true);
// Below required for geolocation
browser.getSettings().setGeolocationEnabled(true);
//parse
Parse.initialize(this, "", "");
ParseAnalytics.trackAppOpened(getIntent());
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
//enable all plugins (flash)
browser.getSettings().setPluginState(PluginState.ON);
I try use this code,
我尝试使用这段代码,
browser.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");
I still got same result. Can anybody help me to solve my problem ? Thank's
我仍然得到相同的结果。任何人都可以帮我解决我的问题吗?谢谢
1 个解决方案
#1
-1
Try setting the actual user agent for your device. It'll vary depending on Android version etc, so never hard-code this value, you have to read it:
尝试为您的设备设置实际的用户代理。它会因Android版本等而有所不同,所以永远不要硬编码这个值,你必须阅读它:
//get the UA of the current running device:
String userAgent = browser.getSettings().getUserAgentString() ;
//set the UA of the webview to this value:
browser.getSettings().setUserAgentString(userAgent);
#1
-1
Try setting the actual user agent for your device. It'll vary depending on Android version etc, so never hard-code this value, you have to read it:
尝试为您的设备设置实际的用户代理。它会因Android版本等而有所不同,所以永远不要硬编码这个值,你必须阅读它:
//get the UA of the current running device:
String userAgent = browser.getSettings().getUserAgentString() ;
//set the UA of the webview to this value:
browser.getSettings().setUserAgentString(userAgent);