Something new, writing Android App in HTML 5

I wanted to write an App for my Android Tablet, something easy so I could get a basic understanding of what it would take to write an app. I figured that I could knock something out fairly quickly, but I didn’t know it would be this easy.

I’m a fairly big user of Eclipse, so install the the Android SDK kit and off I went.

I created a New Android Project and edited the main.xml, so it look like the following.

— code starts—

<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                     android:layout_width="fill_parent"
                     android:layout_height="fill_parent"
                     android:orientation="vertical">
  <WebView
                     android:layout_width="fill_parent"
                     android:layout_height="fill_parent"
                     android:id="@+id/webView" />
</LinearLayout>
--- code stops ---
I then updated my java code so that would use the webView toolkit and open my HTML 5 app.
--- code starts---
package com.rogerhosto.myandroidapp;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class MyAndroidAppActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		WebView webView = (WebView)findViewById(R.id.webView);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.loadUrl("file:///android_asset/www/index.html");
	}
}

— code stops —

Then I create a www directory in existing assets directory and created index.html for all my HTML5 code. That’s it.

Pretty Easy.

 

Leave a Reply