Category Archives: Android/Java

Posts about Java and Android

iAndroidRemote – Control your Android phone using Apple Remote

Long time readers of my blog, would know that I hack around Arduino. Couple of days ago, I was playing around with Arduino while listening to music from my Android phone. I wanted to increase the volume of the song that was playing.

At that moment an idea struck me and I thought it would be cool if I can control the volume using some kind of remote. I opened my bag and found an old Apple remote.

Couple of hours later, I was continuing hacking around Arduino, listening to music from my Android phone, but now if I had to change the volume or change the track, I don’t have to reach for my phone, I can do it using my Apple remote itself 😉


If you want to know more about how I did it, or want to try it out yourself, then head over to the project page, where I describe the entire process including the schematics and the source code for both Arduino and Android that I am using.

Try it out and let me know how it works for you. Happy hacking 😉

Posted in Android/Java, Arduino | Tagged , , | 5 Comments

Sharing content in Android using ACTION_SEND Intent

Very often, you might want to enable the ability for users to share some content (either text, link or an image) from your Android app. Users can share the content using email, twitter, Facebook, sms or through numerous other ways.

The users might already have installed some custom apps for each one of the above service. So instead of coding all these again, it would be really nice (for both your users as well as for you as a developer) if you can invoke any one of these apps, where users want to share content from your app.

Sharing text

Android provides a built-in Intent called ACTION_SEND for this purpose. Using it in your app is very easy. All you have to do is to use the following couple of lines.

In my phone, it invokes the following dialog box listing the apps that have registered to get notification for this intent.


Sharing binary objects (Images, videos etc.)

In addition to supporting text, this intent also supports sharing images or any binary content. All you have to do is to set the appropriate mime type and then pass the binary data by calling the putExtra method.

Registering for the Intent

If you want your app to be listed when this Intent is called, then you have to add an intent filter in your manifest.xml file

android:mimeType specifies the mime type which you are interested in listening.

Happy sharing 😉

Posted in Android/Java | Tagged , , | 100 Comments

FeedStats, my first Android app

Just a quick note to you let you guys, that I have just pushed my android app to the market. 🙂

It’s called FeedStats and it allows you to get the stats of a feedburner feed url and shows the data in a graphical format.

I created this app to demonstrate how we can draw graphs in android using JavaScript in a HTML page and then embedding it inside a webview.

If you have an android phone, then you can download it from the Android market, by searching using the term “FeedStats”. Try it out and let me know if you have any feedbacks/comments.

The entire source code of the app is available at my github account. Download and play around with it.

Posted in Android/Java | Tagged , , | 10 Comments

Making Arduino talk with Android using Amarino

Last week, I gave a talk + demo about using Amarino to make both Arduino and Android talk to each other in Bangalore Open source Hardware meetup

I have uploaded the slides which I used for the talk to my slideshare account and you can download it from there or view them here.

Making arduino-talk-with-android-using-amarino from Sudar Muthu

The slide also includes the schematic diagram for the circuit which I used for the demo. The source code that I used for the demo can be downloaded from the below links

Posted in Android/Java, Arduino, Events/Conferences | Tagged , , , | 3 Comments

Adding additional account to Android phone and buying paid apps in India

After paid apps were introduced in Android market for Indian users, I wanted to buy a couple of them. But it took me a couple of days to do it, because of a variety of related and un-related issues. I thought of documenting it here, so that it would be useful for others who are facing the same problem.

The first issue that I faced was that, I have associated my phone with my Google App account and not a regular gmail account. Because of this, I was not able to use Google Checkout to buy paid apps. To fix this, I was supposed to add another Google account that has Google checkout enabled.

The second issue is that, there is some bug in android which doesn’t allow you to add additional accounts. The symptom of this bug is that you will get a error message which says “You don’t have a network connection”, even though you are connected through wifi or gprs. It took me a couple of days to figure out that it is a bug. Searching the internet revealed, that this bug is found across devices and across Android OS versions. I really wonder why Google has not fixed it yet.

Anyways, after searching sometime, I found out a relatively easy fix. You can try to add the account using the Youtube app. The following are the steps to do that.

  • Open up your Youtube app
  • Select menu –> My account and then click Add Account. Enter the new email address
  • Go back to your home screen and then select Menu -> Settings -> Accounts & sync
  • Set sync settings there and put in the password when prompted

Now you can go to the Market app and start buying paid apps. 🙂

Posted in Android/Java | Tagged , , , | 4 Comments

Generating graphs in Android

I wanted to visualize data using graphs in one of the Android app that I was developing and found that Android SDK don’t provide a good graphing API, which you can use out of the box.

You have to either using Canvas 2D graphics to draw your graphs from scratch or use some commercial components.

If you can assume that some form of Internet connection will be available then you can use Google Graphs API to get the graph and embed it in a webview control. But I didn’t wanted to make that assumption and so I started to search for a good graph component, which I can use in my app.

After some frustrated search attempts, I stumbled upon a wiki at rapid android, which explained, how you can use jQuery based JavaScript library flot to draw graphs for android. At first I dismissed it, since I didn’t wanted to assume that an active Internet connection would be available for my app. But after reading it for the second time, I realized that the graphs could be drawn using HTML and JavaScript files stored locally, without the need to be connected.

So I wrote a sample app to try it out and it really worked out great. I thought of posting the source code and a little writeup about it so that it would be useful for others as well.


So my goal was to create graphs in android using any JavaScript or HTML that are stored locally. The app and the graphs should work even if access to Internet is not available.


Flot is a jQuery based JavaScript library that was easy to use and created powerful and feature-rich graphs. The main advantage of flot is that it is completely compatible with the browser that is available in android.

Setting up webview

The first thing that we have to do is to setup webview, which will be rendering the HTML page, on which we will be drawing the graph. You can add the webview control to your android layout.xml file using the following code.

Once it is added to your layout.xml page, you can access it in your activity using the following code.

Adding the HTML page to assets folder

The next step is to place the HTML, CSS and JavaScript files into the /assets folder. You should have the files only in the assets folder and not in any arbitrary folder because webview can only open files which are placed in the /assets folder.

Also add the flot and jQuery files into the /assets folder and refer to them with relative urls in your HTML file. You can also checkout the HTML file that I have created for reference.

Once you add the HTML file, you can load it in your webview using the following code snippet.

Connecting Java and JavaScript

We will be adding an interface to the webview  (by calling the addJavascriptInterface method) which will allow us call JavaScript methods from the Java code.

In the Java side, we have to create a separate class, which can be used to interact with JavaScript and pass data between the two worlds. Check out the following code snippets to find out how to do it.

Check out the StatsGraphHandler class in my sample project for reference.

Enjoy your graph

That’s it 🙂 Fire up your app and you can see the excellent graph generated.

Advanced usage

You can also add some buttons in the HTML page, which can directly interact with the graph. For other options, check out flot’s documentation.

Sample Code

You can download the complete code of the sample app that I created from my github account.


Posted in Android/Java | Tagged , , , | 19 Comments

CouchDB on Android webcast

Just a quick note to let you know that O’Reilly is conducting a webcast on using CouchDB on Android phone tomorrow, Sep 22, 2010 at 10 AM PST (10:30 PM IST).


Following is the agenda

  • Why CouchDB on a phone is awesome, and what you can do with it
  • Deploying existing CouchApps to Android CouchDB
  • Using CouchDB in native Android apps

Aaron Miller who works for is going to conduct this webcast. If you are interested in Android or CouchDB, then you should definitely attend it.

You can register for the webcast from the event page.


Here is the video of the webcast. You can also view it as an Adobe meeting achieve.

Posted in Android/Java, Database Programming | Tagged , , | 3 Comments

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.


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


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


Click Ok, to download the 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


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/Java, Gadgets | Tagged , | 4 Comments

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.


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/Java | Tagged , , | 5 Comments

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.


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


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/Java | Tagged , , | 9 Comments