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 😉
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.
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.
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.
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.
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.
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
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.
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.
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 😉
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.
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.
Getting Authenticated with Twitter
Webview and webview Client
List headers and footers
Concurrent Programming with Threads
Tweeting from App
Using AsynTask to run many Concurrent tasks
Adding style to the App
Selectors and XML Graphics
Designing for multiple screen dimensions
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