featured, Technology

My first Android app

Hello all

Today I finally started some Android development. I’m not a Java developer and have never done mobile development before but I was keen to get started. So as usual, Hello World was the first app I had to build.

I started off with AppInventor, which I found was great for drag-n-drop GUI and programming. This was great to start off with and get familiar with some of the GUI components. However, I wanted to see and write code. So I headed over to http://developer.android.com and clicked on getting started. To be honest I skipped the “What is Android?” section and moved to “Application Fundamentals”.

Android SDK installed, Eclipse configured, Android Virtual Device setup and we are GO. New Android Project created and compiled. A blank screen 🙂 . It was time to add a couple of UI controls a TextView and CheckBox. I could have used the friendly UI to drag components onto the device “screen” but I thought I should go straight for XML.
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

A TextView followed by a CheckBox underneath. Switch to the Graphical View tab and we get a visual confirmation of these two controls. Simple stuff so far.

Now we want to change the text of the TextView. We can add android:text="caption" to the above XML but that’s static text and boring. Let’s go to the source code in our HelloWorldActivity.java file. The following two lines of java get the TextView control and sets its text property:

final TextView tv =(TextView) findViewById(R.id.textView1);
tv.setText("changed Text");

Similarly for the CheckBox:

CheckBox chkEnable = (CheckBox)findViewById(R.id.checkBox1);
chkEnable.setText("Enable");
chkEnable.setChecked(false);

We can compile and run this. You will see the “changed Text” at the top and right underneath it a check box.

Hello World

Beautiful.

The next step for me was to add some functionality to the Check Box. Here’s the code:

chkEnable.setOnClickListener(new OnClickListener() {

      	  @Override
      	  public void onClick(View v) {

      		if (((CheckBox) v).isChecked()) {
      			Intent in = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
      			startActivity(in);
      			Toast.makeText(HelloWorldActivity.this,
           		 	   "Enable GPS" , Toast.LENGTH_SHORT).show();  			
      		}
      		else {
      			Intent in = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
      			startActivity(in);
      			Toast.makeText(HelloWorldActivity.this, "Disable GPS", Toast.LENGTH_SHORT).show();

      		}

      	  }
      	});

Here we add a onClickListener to detect when the Check Box has been clicked/tapped. In this we have a onClick() method which defined the actions to take when the check box is clicked. Here I am opening the Location settings of Android and showing a toast notification. I should mention here what an “Intent” is. An Intent is a message for a specific activity,  service or broadcast. For Activities, this could be the action to perform, and for Broadcast this could be a message. Above I’m using an Intent to perform the action of starting the location settings Activity. I then use Toast.makeText to show a notification.

So far so good. This wasn’t a big challenge so I set out to add Google Maps. I already had the functionality to open Location settings so I thought this follows on nicely. This is where things get complicated. I won’t post the whole code here but I will link to the tutorials I followed.

[1] http://developer.android.com/guide/topics/location/index.html

[2] http://developer.android.com/resources/tutorials/views/hello-mapview.html

[3] http://developer.android.com/guide/topics/location/obtaining-user-location.html

These give a step by step tutorial to add Google Maps and also acquire a position fix using either network or GPS. So here’s one I made earlier:

Hello World with Maps, Notification and Location information

Here I have taken the location information and displayed it in my TextView. The little Android shows the current position and the Toast notification is triggered by checking the “Enable” check box.

You can get this apk here. This is for devices with Android 4.0 and above. I have only tested this on Samsung Galaxy Nexus and with a help of a friend on Samsung S II.

Disclaimer: This software is provided “as is” with no warranty. (I have always wanted a chance to write that 😛 ).

Advertisements
Standard
featured, Technology

Google Chrome (beta) for Android

Early his week Google released a beta version of their Chrome browser for Android 4.0 (Ice Cream Sandwich). You can download the beta from Android Market.

The native web browser in Android has shared the webkit with the desktop version of Chrome for a while now. The performance improvements are related to JavaScript execution and it feels well optimised for a mobile environment. The UI is very simple and similar to the desktop version. Some nice features like tab organisation are well implemented.

Instead of talking about the UI, here are some screenshots.

Try out Chrome and let me know what you think.

Standard
featured, Technology

Samsung Galaxy Nexus (Updated)

So I finally got my Galaxy Nexus delivered and it is a beauty!

In this post, I’m not going to talk about all the features of the phone or of Ice Cream Sandwich. I’m going to talk about my experience of using the Galaxy Nexus and moving from a Blackberry to Android.

The move to Android

The first impression was that ICS looks very sleek. Very smooth and shiny. Compared to Blackberry OS6, the interface flows much better.

Obviously a major change was moving from the awesome hardware keyboard to a soft keyboard on Android. The change is made difficult by the lack of physical feedback. Sure the Galaxy Nexus vibrates on key press but that is not a replacement for a physical push of the button. So it’s safe to say I miss the keyboard on the Blackberry!

Next on the list is the screen. Here’s an understatement to describe it: it’s huge! No really it maybe smaller than the Samsung Note or the Dell Streak but it’s still huge! The plus side to this, well there are several. More screen real estate, bigger keys on the soft keyboard and of course the Galaxy Nexus has a half HD screen. The sAMOLED screen is easy on the eyes while being sharper and producing more colours. The 1280×720 resolution is as expected, amazing. Having a 4.6 inch screen is not good for the battery. From the android’s battery manager, about 40-50% of the battery is consumed by the screen alone. The Galaxy Nexus has a 1750mAh battery which isn’t big but survives for a day without any heavy CPU/GPU usage.

Do I miss BBM? No. I was never a big fan or user of BBM but now I have WhatsApp Messenger on which pretty much all my friends are available. I never use to watch any videos on the BB on such a small screen. The HD screen makes watching movies a pleasure. Reading books is also good, Google Books is available out of the box and syncs with your account. I found Moon+ Reader free to read other formats like epub.

NFC

Near Field Communications. Right now in the UK, there are no practical uses that I’m aware of. No Google Wallet, No Mastercard PayPass or Oyster travel card (London Underground travel card). I found the “NFC TagInfo” application very useful in reading the tags. For most tags it is able to read the ID and memory block size etc. Obviously most tags are encrypted and to decrypt, you can enter the Access Keys.

What is novel is that the NFC antenna is actually embedded in the battery itself. I’m not sure what technical advantage is of doing this compared to embedding it in the back cover. I would like to see more practical applications of this technology sometime soon in the UK.

All in all, I’m really liking Android 4.0 on Samsung Galaxy Nexus. I am glad to have moved on from Blackberry and as my friends say I have “seen the light” now. haha

I hope you are enjoying your Galaxy Nexus and I would recommend upgrading if you are due.

Updates:
I didn’t mention the notification indicator before. Well it’s located in the bottom bezel of the phone and is a 3 colour LED. Although here are no options in ICS to choose the notification colour, I have noticed that Facebook notifications have the blue light whereas Gmail and others have the generic milky multi colour.

Standard