RU EN

Lada-studio. Full stack Web development. lada-studio.com
Corporate website

Corporate website

Corporate portal for the company!
Internet-shop

Internet-shop

Modern and fast website!
Social network

Social network

Unique solutions!
Personal website

Personal website

For your business!

WEB

Full stack Web development...

Full stack Web development...
Website friendlystyle.ru
Website you-paint.pro
Website med-3.ru

OUR SOLUTIONS JAVA

WebView for Android (Java).

Application of Android System WebView... Code example  

WebView is a component of the Android platform that allows you to create full-fledged web applications that run inside Android mobile applications...

WebView allows you to display the content of web pages both from a remote site and from local ones stored in application resources. It is increasingly used as a separate development stage or as an MVP (Minimal Viable Product)...

Java

Sample code (MainActivity.java) for WebView Android application.


public class MainActivity extends AppCompatActivity {
    //Overriding navigation buttons
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
	
    WebView webView;
    @SuppressLint("SetJavaScriptEnabled") //disables JavaScript enable warning
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //bottom navigation bar
        Window w = getWindow();
        w.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

        //disables the night theme
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

        //expands the application to full screen
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        //applies the layout to the current screen
        setContentView(R.layout.activity_main);
        webView = new WebView(this);

        //new settings for WebView element
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setAllowFileAccess(true); //opens internal pages in the application
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //caching settings
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

        //create a new WebViewClient
        webView.setWebViewClient (new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request){
                if ("your-website.com".equals(request.getUrl().getHost())) {
                    //your website "your-website.com" 
                    return false;
                }
                webView.stopLoading();
                Intent intent = new Intent(Intent.ACTION_VIEW, request.getUrl());
                startActivity(intent);
                return true;
            }  

        });  

        webView.loadUrl("http://your-website.com/"); //your website "your-website.com"
        //You can also download your html page from the Assets directory. 
        //webView.loadUrl(("file:///android_asset/index.html"));
        setContentView(webView);

    }
}
						
Everything is simple, if you don’t complicate anything!
Here is a sample code (MainActivity.java) for a WebView Android application... WebView allows developers to bridge the gap between web technologies and native Android technologies!