A
A
Anton Vertov2018-02-01 02:43:15
Java
Anton Vertov, 2018-02-01 02:43:15

How to send a site that I'm not from a smartphone in WebView?

Good day, playing around with WebView, creating a mini-browser for myself. I need to visit the site through my browser "as if" from a computer, and not from a mobile device (so that it does not redirect to the mobile version). Can you please tell me how to send headers to the site that I came from the computer using WebView? This is how I implement WebView

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

    private WebView mWebView;
    /** Called when the activity is first created. */
    @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mWebView = (WebView) findViewById(R.id.webView);

        mWebView.getSettings().setJavaScriptEnabled(true); // Включай JS

        mWebView.setWebViewClient(new MyWebViewClient());
        mWebView.loadUrl("https://yandex.ru");
    }
}

class MyWebViewClient extends WebViewClient
{
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        view.loadUrl(url);
        return true;
    }
}

Many thanks in advance for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Chvalov, 2018-02-01
@1Frosty

webview settings
android-user-agent.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question