Tuesday, January 14, 2014

Write an android app for your site in 5 minutes !

Heyy folk,

After ages huh? yup what can I say, I've been never so busy (or rather lazy). Any how lets wrap up the chitchat and focus on task. So I was totally minding my own business and watching Two and a Half Men when this guy, the architect of a project I'm involved in (check it out said he needs an app done for the website.
I was lazy to do anything, so i protested right away,

why to show the same content of your site in an app when the user can do it by his own browser?

The answer is the user never does. That's right, the user that you are wishing so much wont simply open his browser and goto your site, unless you make him do it? How?

Since this is an android app let's focus on how having an app in android app market (Google Play) helps:

1) Target your audience

You can manage and control the audience of the display of your app something you cannot control when you submit your website link to a search engine

Since the current website I'm involved in is limited to Sri Lanka, It gives us the option of limiting it to those users only

2) Get benefit from random searches

That's right, there are some people who search things like "fun", "dance", "food", "bla" in the market search. So if your app is catchy this is a way to grab some users to your site. Plus point is they are also interested on the content of your site.

3) May be some advertisements

You could actually sell some ads on the mobile app of the site more easily than your actual website

4) Spreading the word

Yup, that's the best marketing tool ever! What else than having a mobile app for your own site to add some class to your business? :D (not really)

So enough pros-and-cons, lets get down to business. So when i heard bout the deal I had two ideas in my mind
  1. Serve offline context version of the site
  2. Serve the online version which is more easier

Naturally me being so cheerish, went for option 2. Now here's my plan

Make a new app -> Add a webview -> Load the site in it at the app start

Believe me, if you have everything ready, 5 minutes is more than enough :D

Step 0: Download the Android SDK and stuff
This isnt of course the point of this blog post, so get it from

Step 1: Create new Android Application Project, mine was called wooroll and package com.wooroll.apps

Step 2: Delete the default layout(xml file). WHAT? yup, we just need a webview, what's the point of having a layout for that? :S


  1. package com.wooroll.apps;
  2. import android.os.Bundle;
  3. import;
  4. import android.view.KeyEvent;
  5. import android.view.Menu;
  6. import android.view.Window;
  7. import android.view.WindowManager;
  8. import android.webkit.WebSettings;
  9. import android.webkit.WebView;
  10. import android.webkit.WebViewClient;
  11. public class Home extends Activity {
  12.         //our webview is here
  13.         private  WebView wb;
  14.     @Override
  15.     protected void onCreate(Bundle savedInstanceState) {
  16.         super.onCreate(savedInstanceState);
  18.         //we need to make the app run in fullscreen
  19.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  20.         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  21.         WindowManager.LayoutParams.FLAG_FULLSCREEN);
  23.         //create a new webview instance and make the current activity as its context
  24.         wb = new WebView(this);
  25.         //show it as our view
  26.         setContentView(wb);
  27.         //just to enable javascript
  28.         WebSettings webSettings = wb.getSettings();
  29.                 webSettings.setJavaScriptEnabled(true);
  31.                 //we need to make sure that all URLs are handled in our app            
  32.                 wb.setWebViewClient(new WebViewClient() {
  33.                     public boolean shouldOverrideUrlLoading(WebView view, String url) {
  34.                         view.loadUrl(url);
  35.                         return false;
  36.                     }          
  37.                 });
  39.         //load the website yeyeee :D
  40.                 wb.loadUrl("");        
  41.     }
  43.     //one thing we dont want is the app closing down when the user just wanna go abck
  44.     //so lets map the hardware back to the webview back event
  45.     @Override
  46.     public boolean onKeyDown(int keyCode, KeyEvent event) {
  47.         if (keyCode == KeyEvent.KEYCODE_BACK) {
  48.             wb.goBack();
  49.             return true;
  50.         }
  51.         return super.onKeyDown(keyCode, event);
  52.     }    
  53. }

The code is pretty self explanatory, all it does is making a new webview and navigating it to our site. So it's 90% done.

Step 4: Give internet permission. IMPORTANT ! Without this you app wont be able to load any internet content at all. Goto the app manifest and add this line

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

so it would look like this:

  1. <uses-sdk
  2.        android:minSdkVersion="10"
  3.        android:targetSdkVersion="10" />
  4.     <uses-permission android:name="android.permission.INTERNET"/>
  5.     <application ...

Test the app once to see that it's working without errors.

Step 5: Now the pimping part, we need ICONS.
No need find any image editors and stuff, find a fairly square version of your site logo. I used the original one used to make the favicon. Now use this site to generate the launcher icons :D

Step 6: Get your app set and extract and replace the default icon with yours

Step 7: BUILD IT !

Step 8: Upload to the Google Play and DONE !

Yey, now you have a shining new app for your website , kudos :D

Here are some screens and stuff from our site and app, note that our web site was made with bootstrap to be fully responsive so it by default had no problem being viewed from mobile devices.


All for today, its around 12 AM and I'm really freaking sleeepy, so let's meet again


  1. can you help me :( you can do the same ... the tutorial is great but I do not handle well in android. if not too much trouble I can create what mime for me?

    1. yup, temme which part you need help with? :)