A WebView mobile app shows a web application in the form of a mobile application in a flexible yet fantastic way. In simple terms, a WebView app resembles a website’s view when opened from a mobile browser.
Advantages of a webview app:
1. Replicates a website’s view inside a mobile app
2. Time-saving in terms of time-constrained development
Disadvantages of a webview app:
1. Show the features only available on the web application
2. Tough to add new feature on the mobile-side
Program (Java):
package com.khalnayak.webview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
WebView web;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web = findViewById(R.id.webview);
WebSettings webSettings = web.getSettings();
// JavaScript must be enabled to view the site
webSettings.setJavaScriptEnabled(true);
web.setWebViewClient(new Callback());
// web URL to show the view
web.loadUrl("https://softwarewall.code.blog/");
}
private class Callback extends WebViewClient{
@Override
public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event){
return false;
}
}
}
GitHub Source Code link: https://github.com/Farial-mahmod/Webview-mobile-app
