Step By Step Guide to convert Website into Android Application easily

Are you guys looking to create an android app from your website ? Today we have Step by step tutorial to convert your website into android app in few...
android web app

Are you guys looking to create an android app from your website ? Today we have Step by step tutorial to convert your website into android app in few steps. Stick to this post to learn more 😀

Building android app from website is quite easy you don’t need to be hard android coder all you need to follow few steps and you are ready to go.

 

Well, let’s begin the journey from a Website to an Android Application.

 

To load your responsive website into your Android Application, Android provides a View called “WebView”, WebView loads your website url into the application and it feels like using same website through application. So let’s see how this WebView works in android application.

 

Step 1:

Create a new Android project in the development toolkit you use (here I have used Android Studio).

 

Here choose application with Empty Activity and then finish to create application.

Step 2:

After you created a new application, first thing we need to do is design a layout. So will edit XML file under project files

“WebViewExample/app/src/main/res/layout/activity_main.xml”

 

In this file add WebView component which holds your website content in future.

 

Now we are ready with the design (UI part), which looks like:

 

Step 3:

Now Let us see the logic part i.e. back-end. Which means how this screen containing WebView will show our website’s content. So for that we need to edit our MainActivity.java file in application.

 

Before diving into coding let me explain the logic that how WebView loads our Website’s data into it.

 

WebView is a View that display web pages. This call is the basis upon which you can roll your web pages or any online content into your activity. It uses Webkit rendering engine to display web pages and methods to navigate backward and forward through history, zoom in and out, etc. Basically it loads your website’s url by: webview.loadUrl(“http://www.techsteak.com/”);

 

Note that in order for your activity to load your web pages INTERNET PERMISSION must be added to the AndroidManifest.xml file.

<uses-permission android:name=”android.permission.INTERNET”/>

 

MainActivity.java:

 

public class MainActivity extends AppCompatActivity {

 

   WebView webView;

   @Override

   protected void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_main);

 

       webView = (WebView)findViewById(R.id.WebView);

       webView.loadUrl(“http://www.techsteak.com/”);

   }

}

 

This much of coding will allow you to run application successfully and also your website’s content will be loaded into WebView. It looks like:

 

 

A WebView offers several customization options where we can add our own behaviour. These are:

 

Setting a WebChromeClient subclass, this class is called when something that might impact a browser UI happens, for instance, progress updates and JavaScript alerts are sent here.

 

webView.setWebChromeClient(new WebChromeClient());

 

setting a WebViewClient subclass. It will be called when things happen that impact the rendering of the content, eg, errors or form submissions. You can also intercept URL loading here.

 

webView.setWebViewClient(new WebViewClient());

 

Modifying the WebSettings, such as enabling javascript, setJavascriptEnabled().

 

WebSettings webSettings = webView.getSettings();

webSettings.setJavaScriptEnabled(true);

 

Injecting Java objects into the WebView using addJavascriptInterface(Object, String) method. It allows you to inject java objects into a page’s javascript context.

 

This sums up the basic tutorial for creating an Android Application that contains WebView. There are lot more functions available which allows us to customize WebView further according to our needs. You can do research on it further on Developer.android.com for detail explaination.

 

 

Categories
Android

Android Developer | Programmer
No Comment

Leave a Reply

*

*

advertisment

RELATED BY

  • 10 BEST APP FOR ANDROID (1)

    10 BEST APP FOR ANDROID

    Searching for best Android app related to anything is the most confusing thing. We are always in dilemma in choosing which app to download that will fulfill our purpose....
  • Reasons why android is better than ios

    6 Reasons Why Android is Better Than IOS

    Google’s Android and Apple’s iOS are operating systems used primarily in mobile technology, such as smartphones and tablets. Android, which is Linux-based and partly open source, is more PC-like...