Android browser does not load mobile version

I have a problem with my Android browser. The application works fine on some devices, but doesn’t download the mobile version, when I use Sony Acro S, it always downloads the web version. The first time, I think, maybe this is my version of Android (4.1.2), but I tried on a different device with the same version of os (4.1.2), and the result is a downloadable version of the device, not the web version. Here is my code,

public class MainActivity extends Activity 

{private browser WebView;

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 am trying to 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 have the same result. Can someone help me solve my problem? Thanks x

+4
source share
1 answer

. 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

Source: https://habr.com/ru/post/1533075/


All Articles