Converting A Website Into An Android App

Introduction

 
In this article, I have implemented a simple technique of converting a website into an Android app. I will show you how to easily convert your favorite website into an app. 
 
Requirements
  • Android Studio
  • An Android device or an emulator
STEP 1
 
Open Android Studio and create a new project, as shown in the below steps.
 
android
 
STEP 2  
 
Name your app with whatever you want to, as shown below.
 
android
 
After creating the new project, just modify it with the codes as given below.
 
MainActivity.java is shown below.
  1. package com.example.lokesh.sanjay_abd;  
  2. import android.app.Activity;  
  3. import android.support.v7.app.AppCompatActivity;  
  4. import android.os.Bundle;  
  5. import android.view.Window;  
  6. import android.webkit.WebSettings;  
  7. import android.webkit.WebView;  
  8. import android.webkit.WebViewClient;  
  9. public class MainActivity extends Activity {  
  10.     public WebView webview;  
  11.     @Override  
  12.     protected void onCreate(Bundle savedInstanceState) {  
  13.         super.onCreate(savedInstanceState);  
  14.         requestWindowFeature(Window.FEATURE_NO_TITLE);  
  15.         setContentView(R.layout.activity_main);  
  16.         webview = (WebView) findViewById(R.id.webView);  
  17.         WebSettings webSettings = webview.getSettings();  
  18.         webSettings.setJavaScriptEnabled(true);  
  19.         webview.loadUrl("http://pec.paavai.edu.in/techfinix18/");  
  20.         // modify with your favorite website  
  21.         webview.setWebViewClient(new WebViewClient());  
  22.     }  
  23.     @Override  
  24.     public void onBackPressed() {  
  25.         if (webview.canGoBack()) {  
  26.             webview.goBack();  
  27.         } else {  
  28.             super.onBackPressed();  
  29.         }  
  30.     }  
  31. }   
activity_main.xml as below,
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <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="com.example.lokesh.sanjay_abd.MainActivity">  
  3.     <WebView android:id="@+id/webView" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />   
  4.   
  5. </android.support.constraint.ConstraintLayout>  
In the below Androidmanifest.xml file, we have chosen only the internet access permission.
 
Androidmanifest.xml should be as follows.
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.lokesh.sanjay_abd">  
  3.     <uses-permission android:name="android.permission.INTERNET"></uses-permission>  
  4.     <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">  
  5.         <activity android:name=".MainActivity">  
  6.             <intent-filter>  
  7.                 <action android:name="android.intent.action.MAIN" />  
  8.                 <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>  
  9.         </activity>  
  10.     </application>  
  11. </manifest>  
After all this coding process, just connect your mobile phone or use an emulator for running the app; that’s it. An app with your favorite site is ready now.
Finally, click the Play button above in the tab for Gradle build.
 
Below is the screenshot of the created app. You can generate a .apk by following the process below:
 
In the top menu tab, goto BUILD->build apk.
 
That's all. Your new apk for the Android app has been generated. 
 
android
 

Conclusion

 
In this article, you learned how to convert a website into an Android app using Android Studio easily. Let's see some other Android applications in the upcoming ones.


Similar Articles