How to create an android app from website using android studio in 2019 – Part 1

It’s very easy to create an android app from the currently working website in android studio.

Requirements for converting website to android app:-

  1. Android Studio
  2. Running website

We can do that in few steps:-

1. Start new project in Android Studio

and fill necessary fields as given below.

  • Fill the name of the app project and click on button “Next”.

  • Then select the mobile version for what you want to create the .apk file.

  • Select “Empty activity” from activity section and then click on “Next” button.

  • Now click on button “Finish”.

 Now your coding screen will open as in image and you’ll need to make few changes.


2. Open activity_main.xml page and do following changes.

  • Open the page in text mode by clicking on text button from bottom left.
  • Add this line in tag <android.support.conatraint.ConstraintLayout>
  • Remove the “TextView” section as we will use “WebView” mode.
  • Add following code as “WebView” section.
    Now your activity_main.xml file will be :-
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity"    tools:layout_editor_absoluteY="81dp">

    <WebView        android:id="@+id/webview"        android:layout_width="match_parent"        android:layout_height="match_parent"        tools:layout_editor_absoluteX="0dp"        tools:layout_editor_absoluteY="0dp" />

</android.support.constraint.ConstraintLayout>

3. Replace content of Main_Activity.java with following.

Also you ll need to change the url with your website’s url here.

package in.co.svsoftwares.svsoftwares;

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

public class MainActivity extends AppCompatActivity {
    private WebView mywebView;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mywebView=(WebView)findViewById(R.id.webview);
        mywebView.setWebViewClient(new WebViewClient());
        WebSettings webSettings=mywebView.getSettings();
        mywebView.loadUrl("http://svsoftwares.co.in/");
        webSettings.setJavaScriptEnabled(true);
    }

    public class myWebClient extends WebViewClient{

        @Override        public void onPageStarted(WebView view, String url, Bitmap favicon){
            super.onPageStarted(view, url, favicon);
        }

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

    @Override    public void onBackPressed(){
        if(mywebView.canGoBack())
            mywebView.canGoBack();
        else            super.onBackPressed();
    }

}

4. Replace the content of AndroidManifets.xml file with following.

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="in.co.svsoftwares.svsoftwares">
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:roundIcon="@mipmap/ic_launcher_round"        android:supportsRtl="true"        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

5. Now click on the Run button on top menu and select the simulator or mobile attached to computer for running (testing) the website.

6. Now you will see the app running successfully in the simulator or mobile.





In next tutorials we’ll learn to Add splash Screen for app and also How to add the app in the play store.