Category Archives: Android

Updating HTC Hero (GSM) to Android 2.1

Updating HTC Hero (GSM) to Android 2.1

After waiting for more than a couple of months, HTC finally released the much waited Android 2.1 update for HTC Hero GSM Mobiles in India.

I waited for this update for long time and updated my mobile last week. Thought of sharing the process here so that it is useful for others.

Preparing for the update

The Android 2.1 update consists of two updates. First update prepares your phone and the second update is the actual OS update. Both are OTA (over the air) updates and so you don’t need to download anything to your computer.

When you connect to the internet (either through wifi or through gprs/edge) you will get a prompt which will ask you whether you want to download the upload. If you for some reason clicked later, there is a nice trick to get the prompt again. The trick is to change the data and you will get the prompt immediately.

The first update is around 5 MB. Once the update is done, your firmware build number would be updated. If you have the same build and kernel numbers like the screenshot below then your update has just went fine.

htc-hero-firmware-version

Actual update

As I said before, the first update will prepare your phone for the OS update. In addition to the preparation part, it will update your Youtube player and will also add a new update menu to your phone settings menu, through which you can download the second update.

You can access this menu item by going to Settings->About phone->System Software Updates

htc-hero-check-for-update

Click the check button and it will show the below prompt.

htc-hero-ota-firmware-update

Click Ok, to download the update.

htc-hero-ota-update

This update is around 80 MB. If you don’t have a decent GPRS/Edge plan, then it would good if you could update when you are connected through wifi. Otherwise your phone data bill might go over your roof.

Once you click okay, phone will download the update and will install it. Your phone might restart a couple of times and once everything is done, you HTC Hero mobile will be running the new shinny Android 2.1

Precautions

Since it is an update to the base OS, it is recommended that you follow these precautions

  • Even though the update will not erase your application and data, it is highly recommended that you backup your applications and data before proceeding
  • As I said before, the downloads are more than 80 MB in size and if you don’t have a decent GPRS/Edge connection, it is better to use wifi
  • It might take around an hour for the entire process to get over. So make sure that your phone’s battery is full.
  • Also disable the unlock patters when the update is going on, since the phone might need to restart a couple of times.

I am off to play with the new update in my HTC Hero mobile, meanwhile do let me know how your updating went. Happy updating ;)

Posted in Android, Gadgets | Tagged , , | Leave a comment

Developing Android Apps – Part 2 – Week one – My notes

Developing Android Apps – Part 2 – Week one – My notes

This week, I was not able to attend the full class due to time constraint, since I returned from a vacation on Tuesday. So my notes will not be as detailed as it used to be. I will try to provide detailed notes next week.

Getting authenticated with oAuth

So basically this week, Tony explained how to setup oAuth authentication, so that we can use the Twitter API without explicitly asking for password from the users.

In order to set it up, we have to first register for an app from Twitter. You can follow the screencast at the end of last week’s notes to do that.

Twitter4J

The next step is to include the Twitter4J jar. You can download it from the project homepage and then you have to copy it to the /lib directory of your android project. If you are using windows, then you can follow the steps given in this forum post to add Twitter4J to your android project.

Source code

You can access the source code for this week’s class from the official github repository.

See you all next week with detailed notes :)

Posted in Android | Tagged , , | 1 Comment

Developing Android Apps – Part 2 – Overview – My notes

Developing Android Apps – Part 2 – Overview – My notes

As I mentioned before, Creative tech is conducting part 2 of the Developing Android App class. Like Part 1, I am planning to post my notes here so that it would be helpful for others too.

Introduction

This week, we had the Overview session by Tony (the presenter). The training started off with a brief explanation of the concepts that were covered in Part 1. Tony then explained briefly about Twitter and the explained what are the things that will be covered in the next 5 classes.

The following is the schedule for the next 5 weeks.

Week one

  • Getting Authenticated with Twitter
  • oAuth
  • Twitter4J
  • Webview and webview Client

Week two

  • Advanced ListView
  • List headers and footers
  • Concurrent Programming with Threads
  • Handlers

Week Three

  • Tweeting from App
  • Creating menus
  • Using AsynTask to run many Concurrent tasks
  • Posting tweets

Week Four

  • Adding style to the App
  • Themes
  • Styles
  • Selectors and XML Graphics
  • Designing for multiple screen dimensions

Week Five

  • Posting photos from the app
  • Getting photos from the library
  • Getting photos from the Camera
  • Posting photos with twitpic4J

Homework

The homework for this week is to register an application and get authentication keys to use oAuth with Twitter. This has to be done before the next week class so that you can use to try next week’s code.

Tony has created the following screencast which explains the process of registering your application with Twitter.

There are lot of really interesting things lined up and I am very excited about this course. See you next week :)

You can also subscribe to my blog’s RSS feed or follow me in Twitter to receive updates about my notes for the next sessions.

Posted in Android | Tagged , , | 7 Comments

Android on iPhone

Android on iPhone

Yes, you read the title correctly. Now it is possible to run Android on iPhone (and can have flash too ;) )

Planentbeing from linux on iphone project has successfully ported Android to run on iPhone. You can see the following video where he demos dual booting iPhone with android.

Man, seriously this guy is a genius and I really adore his reverse engineering skills.

You can also download pre-built images and source and can try it out, if you have an old iPhone lying around.

Posted in Android, iPod/Apple | Tagged , | 2 Comments

Free online course on developing android applications using Java – Part 2

Free online course on developing android applications using Java – Part 2

CreativeLive who conducted a free 6 weeks course on developing Android applications with Java are back again with a follow up course. The part 2 course is also a 6 weeks course (like part 1) and will be conducted by Tony Hillerson, who also conduced the first course.

In this course, a Twitter client would be created and will cover OAuth, access the Twitter APIs, and also how to post photos to Twitter amount other things.

The part 2 of this course is also free to watch live, like the first course. You can check out the schedule in the official page.

If you have attended the first course or if you are interested in Android, then do register for the course, at the official page and follow it up. :)

Posted in Android | Tagged , , , | 3 Comments

10 Open Source Android Apps which every Android developer must look into

10 Open Source Android Apps which every Android developer must look into

I used to read code from popular open source projects to see how others implement certain functionalities and also to learn from them. (I am a firm believer of the fact that you have to read good code to write good code)

Recently I have been following up a couple of good open source Android apps and thought of listing them here so that it could be useful for others.

Sample Apps by Android Team

Could there be a better way to start without looking at the code of the developers who developed the framework? ;) These are 15 different android sample apps created by the core developers of the Android framework. These include a couple of games, photostream, time display, home screen shortcuts etc.

url : http://code.google.com/p/apps-for-android/

Remote Droid

RemoteDroid is an android app which turns your phone into a wireless keyboard and mouse with touchpad, using your own wireless network. You can learn lot of things like connecting to a network, controlling user finger movement etc from its source.

url: http://code.google.com/p/remotedroid/

TorProxy and Shadow

TorProxy is an implementation of Tor for Android mobiles. Together with Shadow, it allows you to browse website anonymously from your mobile phone. You can learn about tunnelling socket connections, managing cookies etc by reading its source code.

url: http://www.cl.cam.ac.uk/research/dtg/code/svn/android-tor/ and http://www.cl.cam.ac.uk/research/dtg/android/tor/

Android SMSPopup

It is an Android app that intercepts incoming text messages and displays them in a popup window. Apart from being a time saver, this app also shows us how to interface with the built-in app that manages SMS.

url: http://code.google.com/p/android-smspopup/

Standup Timer

Standup Timer is an Android application that acts as a simple, stand-up meeting stop watch. It can be used to ensure your stand-up meeting finishes on time, and gives all the participants an equal share of time to state their progress. You can learn how to use the timer functionality by reading the source code. Also this apps has clear distinction between view, model etc and has lot of util methods which we can reuse in our app.

url: http://github.com/jwood/standup-timer

Foursquare

It is a four square client for android. This app is basically divided into two components; the API (com.joelapenna.foursquare) and the Android front-end (com.joelapenna.foursquared). Reading the source code you can find out how to make synchronous, multi-threaded, http connections.

url: http://code.google.com/p/foursquared/

Pedometer

The pedometer app tries to take the number of steps you take every day. Even though the count is not accurate, you can learn different things like interacting with accelerometer, doing voice updates, running background services etc by reading its source code.

url: http://code.google.com/p/pedometer/

opensudoku-android

OpenSudoku is a simple open source sudoku game. You can learn how to display things in a grid in your view and also how to interact with a website by reading its source code.

url: http://code.google.com/p/opensudoku-android/

ConnectBot

ConnectBot is a Secure Shell client for the Android platform. There are lot of good things about this app’s source code. Check it out for yourself :)

http://code.google.com/p/connectbot/

WordPress for Android

How can you expect a list of apps from me without mentioning WordPress ;) This android app is from the official WordPress development team. You can learn how to make XMLRPC calls (in addition to other cool things) by reading its source code.

url: http://android.svn.wordpress.org/trunk/

If you got any good open source android apps from which we can learn something, then do leave a comment and I will add them up here, till then happy reading :)

Posted in Android | Tagged , , | 8 Comments

Developing Android applications in Java – Session 3 – My notes

Developing Android applications in Java – Session 3 – My notes

This week in the Android course, Tony taught about the storing and retrieving information from database. Android has a bundled SQLite database and your app can store and retrieve information by creating a new database. The database that is created by an application is available only to that application and no other application can access it.

SQLiteOpenHelper

Android SDK provides a class called SQLiteOpenHelper which can be used for interfacing with this SQLite database that is associated with your application.

SQLiteOpenHelper has two methods which can be used for creating/updating the database. They are the following.

onCreate

The onCreate() method gets called when the app gets installed for the first time. The SQL code to create the database should go in this method. In addition to the SQL code we should also specify a version number for the database which will be used subsequently during upgrades.

onUpgrade

The onUpgrade() method gets called when the app is upgraded or if the version number specified in the app is greater than the one which is present in the database. Typically this function contains Alter table SQL code which will be used to upgrade the database.

In addition to the above two methods, the SQLiteOpenHelper also has other methods which can be used to access the database. One such method is getWritableDatabase()

getWritableDatabase

The getWritableDatabase() method will return a SQLiteDatabase object which has reference to the database. You can read more about this method from android documentation.

In addition to these methods, the SQLiteOpenHelper class other methods but the above there are the notable ones. You can read more about the SQLiteOpenHelper class from the android documentation.

Selecting data from the database

To selected data from the database, we have to call the query() method on the SQLiteDatabase object which is returned by the getWritableDatabase() method above.

The query() method returns an object of type Cursor, which can be iterated over to retrieve the resultset. The following code snippet explains the query() method.

private void loadTasks() {
	currentTasks = new ArrayList<Task>();
	Cursor tasksCursor = database.query(TASKS_TABLE,
			new String[] {TASK_ID, TASK_NAME, TASK_COMPLETE},
			null, null, null, null, String.format("%s,%s", TASK_COMPLETE, TASK_NAME));
 
	tasksCursor.moveToFirst();
	Task t;
	if (! tasksCursor.isAfterLast()) {
		do {
			int id = tasksCursor.getInt(0);
			String name = tasksCursor.getString(1);
			String boolValue = tasksCursor.getString(2);
			boolean complete = Boolean.parseBoolean(boolValue);
			t = new Task(name);
			t.setId(id);
			t.setComplete(complete);
			currentTasks.add(t);
		} while(tasksCursor.moveToNext());
	}
}

Inserting data into the database

In order to insert the data into the database we have to call the insert() method of the SQLiteDatabase. The data that needs to be inserted should be added to a ContextValues object and then passed to the insert() method. The ContextValues object is like a HashMap which contains the key and the value for each column of the row that will be inserted.

The insert() method returns the id of the row that was inserted. The following code snippet explains the insert() method.

public void addTask(Task t) {
	ContentValues values = new ContentValues();
	values.put(TASK_NAME, t.getName());
	values.put(TASK_COMPLETE, Boolean.toString(t.isComplete()));
 
	t.setId(database.insert(TASKS_TABLE, null, values));
	currentTasks.add(t);
}

Updating data in the database

To update data in the database we have to call the update() method of the SQLiteDatabase object. Like the insert() method, the data that needs to be updated should be passed in a ContextValues object.

The following code snippet explains the update() method.

public void saveTask(Task t) {
 
	ContentValues values = new ContentValues();
	values.put(TASK_NAME, t.getName());
	values.put(TASK_COMPLETE, Boolean.toString(t.isComplete()));
 
	long id = t.getId();
	String where = String.format("%s = %d", TASK_ID, id);
	database.update(TASKS_TABLE, values, where, null);
}

Deleting data from the database

To delete data from the database we have to call (guess what ;) ) the delete() method of the SQLiteDatabase objet. The delete() method takes the where condition based on which the rows will be deleted.

public void deleteTasks(Long[] ids) {
	StringBuffer idList = new StringBuffer();
	for (int i =0; i< ids.length; i++) {
		idList.append(ids[i]);
		if (i < ids.length -1 ) {
			idList.append(",");
		}
	}
 
	String where = String.format("%s in (%s)", TASK_ID, idList);
	database.delete(TASKS_TABLE, where, null);
}

You can read more about this method from android documentation.

Demo App Sourcecode

The demo TaskManager app that we have been using in the previous classes was modified to store the tasks in the database. You can find the source code from my github page. I am also working in this week’s homework and will be posting the explanation and source code once I am done.

You can also subscribe to my blog’s RSS feed or follow me in Twitter to receive updates about my notes for the next sessions.

Posted in Android | Tagged , , , , | 1 Comment

Using ArrayAdapter and ListView in Android Applications

Using ArrayAdapter and ListView in Android Applications

This week’s homework in the android class was to create a simple ListView using ArrayAdapter instead of generic ListAdapter.

ArrayAdapter

ArrayAdapter is a special kind of ListAdapter which supplies data to ListView. You can refer to my notes for last week to know about ListView and ListAdapter. You can also read about ArrayAdapter in android documentation.

Adding views

First create an empty android project. Then edit the main.xml layout file to add a ListView. Then create another layout xml file which will contain the TextView (or any component) that will be displayed within the ListView.

Editing Activity

The next step is to change the generated activity class to extend from ListActivity. This is very important because only a ListActivity will be able to display the ListView.

Binding the adapter

The next step is to bind the ArrayAdapter to the ListActivity. We can do this by calling the setListAdapter() method.

To this method we have to pass an object of type ArrayAdapter. You can pass an object reference to this method or we can even create a new anonymous method like below.

setListAdapter(new ArrayAdapter&lt;string&gt;(this, R.layout.list_item, strings) {
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row;
 
		if (null == convertView) {
			row = mInflater.inflate(R.layout.list_item, null);
		} else {
			row = convertView;
		}
 
		TextView tv = (TextView) row.findViewById(android.R.id.text1);
		tv.setText(getItem(position));
 
		return row;
	}
});

We have to override the getView() method of the ArrayAdapter class to create the TextView (or any other component) which will be created for each list.

Finishing up

So that’s it, you are done. :) All you have to do now is to save the project and run it in the emulator. If everything is done properly, then you can see the list of items displayed in the ListView like below.

android-listview

Source code

I have uploaded the entire project source code into github and you download it from there and verify it with your code.

Try to complete the homework, before the next session and do come back to view the notes and the homework for the next session too. :)

You can also subscribe to my blog’s RSS feed or follow me in Twitter to receive updates about my notes for the next sessions.

Posted in Android | Tagged , , | 6 Comments

Developing Android applications in Java – Session 2 – My notes

Developing Android applications in Java – Session 2 – My notes

Like last week, I attended the session on Developing Android applications in Java by Creative Techs and O’Reilly and here are my notes which I took during the session.

Replace TextView with ListView

In this week’s session, the demo app that was created last week was modified to use the ListView element instead of TextView.

The ListView provides a nice UI for displaying the list of tasks together with a checkbox to indicate whether they were complete or not.

Screenshot

You can see the new UI of the application in the following screenshots.

android-listview

ListView and ListAdapter

ListView is a control which can be used for creating list of scrollable items. The data to the ListView will be provided by ListAdapter.

You can think of ListView as the “view” component in a MVC framework and ListAdapter as the “model”

The class which is going to act as the ListAdapater should implement following methods

  • getCount()
  • getItem()
  • getItemId()
  • getView()

You can read more about ListView and ListAdapter from android documentation.

Adding ListView

To add ListView to any activity, we have to include the <ListView /> tag to the activity’s layout xml. In our sample app, the ListView tag is added to the main.xml file.

The Activity class that uses ListView should implement the ListActivity instead of plain Activity class. In our sample app, the ViewTasksActivity class is derived from the ListActivity class.

Magic ids

Android SDK provides some predefined ids which can be used some specific purposes. One such “magic id” is android:empty.

We can assign this to any element that we want to be displayed when the ListView is empty.

Homework

This week’s homework is to Build a simpler (but less flexible) way to load data into a list using an ArrayAdapter (instead of a BaseAdapter). I would be completing the homework and would be posting the explanation and the source code later this week. So stay tuned :)

Source code

I have uploaded source code for yesterday’s session in github and you can download it from there. I am also working in this week’s homework and will be posting the explanation and source code once I am done.

You can also subscribe to my blog’s RSS feed or follow me in Twitter to receive updates about my notes for the next sessions.

Posted in Android | Tagged , , | 4 Comments

Using preference API in Android applications

Using preference API in Android applications

This week’s homework in the android class was to persist the task information in the sample TaskManager application across program runs, which was created during the class.

Preference API

Android provides a preference API, using which we can store task information. The preference API is very simple to use and all we have to do is to get the instance to the preference object from the Application object and then call the getString() and putString() method.

Serializing ArrayList to string

The only tricky part of the home work is that, since the preference API supports only storing and retrieving of strings, we have to serialize and de-serialize the ArrayList object which has the list of tasks into string.

Instead of writing my own code to do this conversion, I used the code from the Apache Pig project. You can check out the class from the pig’s github page.

Storing the task

In the addTask() method of the TaskManagerApplication class, we have to get the instance of the shared preference and then store the serialized ArrayList using the putString() method.

	public void addTask(Task t) {
		assert(null != t);
		if (null == currentTasks) {
			currentTasks = new ArrayList<task>();
		}
		currentTasks.add(t);
 
		//save the task list to preference
		SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE);
		Editor editor = prefs.edit();
		try {
			editor.putString(TASKS, ObjectSerializer.serialize(currentTasks));
		} catch (IOException e) {
			e.printStackTrace();
		}
		editor.commit();
	}

Retrieving the task

Similarly we have to retrieve the list of tasks from the preference in the onCreate() method

	public void onCreate() {
		super.onCreate();
		if (null == currentTasks) {
			currentTasks = new ArrayList<task>();
		}
 
		//		load tasks from preference
		SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE);
 
		try {
			currentTasks = (ArrayList<task>) ObjectSerializer.deserialize(prefs.getString(TASKS, ObjectSerializer.serialize(new ArrayList<task>())));
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

Finishing up

So that’s it, you are done. :) All you have to do now is to save the project and run it in the emulator. If everything is done properly, the tasks that you enter will be saved even after you restart the app.

Source code

I have uploaded the entire project source code into github and you download it from there and verify it with your code.

Try to complete the homework, before the next session and do come back to view the notes and the homework for the next session too. :)

You can also subscribe to my blog’s RSS feed or follow me in Twitter to receive updates about my notes for the next sessions.

Posted in Android | Tagged , , | 6 Comments