Convert Website into Android App In Android Studio: Step By Step

In this Android tutorial, we will make an app which will demonstrate how to convert a website into an android app in the Android studio. This app will simply load a URL of any website. But make sure that the website which you want to convert into the app should be responsive. We will use google.com in our app.

Useful links

Steps to convert website into android app

  • Select AndroidManifest.xml

In this file, we will add internet permissions. So add the following line of code

 
<uses-permission android:name="android.permission.INTERNET" /> 
  • Select main_activity.xml

    In this file, we need only webview widgets. Drag and drop webview or add code manually. You can adjust height and width.

    <WebView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/webView" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true"/>
    
    • Select main_activity.java file

    In this file we Firstly we will create an instance of webview and bind it to id of this webview which we have given in xml file. Now we need some web settings. So we will create an instance of WebSettings and add this code  WebSettings webSettings = myWebView.getSettings(); .Now we need to set javascript to true. So we will add this code  webSettings.setJavaScriptEnabled(true); .Now to load the url we will use method loadurl(); and pass the url of your website. Now when our website will be loaded, we need to set some settings for events or clicks on website links. For that we will add setWebViewClient(new WebViewClient()); . We can make new java class to modify the click events. Now one important thing is that when our website is loaded in android app and if we click on links in website, no doubt next page will be loaded but we can not go on a back page by pressing back button. We have to write some code for that. We can use onBackPressed() method to handle the back clicks. We will check if we can go back or not. So read following code carefully. 

     

    private WebView myWebView;
    
        @Override
    
        protected void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_main);
    
            myWebView = (WebView)findViewById(R.id.webView);
    
            WebSettings webSettings = myWebView.getSettings();
    
            webSettings.setJavaScriptEnabled(true);
    
            myWebView.loadUrl("http://www.easyonlineconverter.com");
    
            myWebView.setWebViewClient(new WebViewClient());
    
        }
    
     
    
    
        @Override
    
        public void onBackPressed() {
    
            if(myWebView.canGoBack()) {
    
                myWebView.goBack();
    
            } else {
    
                super.onBackPressed();
    
            }
    
        }
    
    

    This is all about MainActivity.java. Now you can test your app. It should load Google’s homepage.

    Summary

  • I hope now you understand how to convert a website into an android app. This is very basic app. You can do a lot more things with the app. For example, you can add processing bar, a sharing button, a menu etc. For any query, you can ask in the comment section. I will recommend you to read my more tutorials on Android development.

Leave a Reply

Your email address will not be published. Required fields are marked *