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.
STEP 2
Name your app with whatever you want to, as shown below.
After creating the new project, just modify it with the codes as given below.
MainActivity.java is shown below.
- package com.example.lokesh.sanjay_abd;
- import android.app.Activity;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.Window;
- import android.webkit.WebSettings;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- public class MainActivity extends Activity {
- public WebView webview;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.activity_main);
- webview = (WebView) findViewById(R.id.webView);
- WebSettings webSettings = webview.getSettings();
- webSettings.setJavaScriptEnabled(true);
- webview.loadUrl("http://pec.paavai.edu.in/techfinix18/");
-
- webview.setWebViewClient(new WebViewClient());
- }
- @Override
- public void onBackPressed() {
- if (webview.canGoBack()) {
- webview.goBack();
- } else {
- super.onBackPressed();
- }
- }
- }
activity_main.xml as below,
- <?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="com.example.lokesh.sanjay_abd.MainActivity">
- <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" />
-
- </android.support.constraint.ConstraintLayout>
In the below Androidmanifest.xml file, we have chosen only the internet access permission.
Androidmanifest.xml should be as follows.
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.lokesh.sanjay_abd">
- <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>
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.
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.