Android Webview in Desktop Mode in Android Studio FREE Source Code

Hi there,

In this Blogpost, 

I am going to give the Complete Source Code for loading the WebView website in Desktop mode in Android Studio. This is working fine. You can watch the Android Tutorials Youtube Channel Video to see the Implementation of this Android WebView in Desktop Mode. The Video and Source Code is given below. 

Android Webview in Desktop Mode in Android Studio FREE Source Code


Android Webview in Desktop Mode in Android Studio FREE Source Code

Here is the Desktop Mode WebView Source Codes:


// Source Code Starts//
package webview.demo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

    WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String webpage = "https://www.fiverr.com";

        webView = findViewById(R.id.webview);

        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setBuiltInZoomControls(true);

        webView.loadUrl(webpage);

        String userAgent = webView.getSettings().getUserAgentString();

        try {
            String androidString = webView.getSettings().getUserAgentString().
                    substring(userAgent.indexOf("("),userAgent.indexOf(")")+ 1);

            userAgent = webView.getSettings().getUserAgentString().replace(androidString,"X11; Linux x86_64");

        }catch (Exception e){
            e.printStackTrace();
        }

        webView.getSettings().setUserAgentString(userAgent);
        webView.reload();

    }
}


// Source Code Ends//


GitHub Gist:


And If you Got the Result from Android Webview in Desktop Mode in Android Studio FREE Source Code then You Subscribe to Android Tutorials Youtube Channel and for any Query feel free to comment I will respond to you as soon as possible.



SUBSCRIBE HERE

Check out other Free Source Codes Android Playlists:


(1) How To Convert A Website Into a Professional Android App Using ANDROID STUDIO  2020 - https://www.youtube.com/playlist?list=PL7nYsbTdViSqf_RlSZvdMshSxCdeE7Dl6

(2) Wallpaper App in Android Studio (using Pexel API) | Android Tutorials - https://www.youtube.com/playlist?list=PL7nYsbTdViSowlrgM6rDQJrIL7lL2ansh


2 Comments

  1. It works!
    I have checked lot of answers in stackoverflow but none of them worked for me.
    finally I found this solution , thanks a lot.

    ReplyDelete

Post a Comment

Previous Post Next Post