android

An Android Java, JSON, and Twitter REST API example

I don't get to parse too much JSON code with Java because the biggest JSON source I work with is Twitter, and I always use the Twitter4J project to interact with their web services. But a few days ago while working on an Android project, I just wanted to access their "Twitter Trends" REST service, and I used Java and the json.org Java library that comes with Android to parse the Twitter Trends JSON feed like this:

Android JSON - Print a JSON string in a human-readable format (for debugging)

Android JSON tip: How to use the JSONObject toString(n) method to debug a JSON string in an Android app, by printing the string in a human-readable format.

While working on an Android project recently, I noticed there is a toString method on a JSONObject object that looks like this:

Android internet access error - java.net.UnknownHostException: Unable to resolve host

Android internet FAQ: I'm getting an internet access error with my Android application that says, "java.net.UnknownHostException: Unable to resolve host (hostname): No address associated with hostname". I think my HTTP/REST code is correct, what's wrong?

If you get an error message like this:

Android screen sizes: xlarge, large, normal, small

A quick note today on Android screen sizes and screen densities. According to the Supporting Multiple Screens document on the Android website, Android screens are broken down into a set of four generalized sizes: small, normal, large, and xlarge. Their sizes in "dp" units are:

Android Activity lifecycle - simple example class (source code template)

With all apologies to Google for copying and pasting this block of source code, in my opinion, this simple example is so good at explaining the Android Activity lifecycle so well that it needs to stand out on its own page:

Android fragments - How to get an Activity widget

Android Fragments FAQ: How do I access an Activity widget from an Android Fragment?

All you have to do in your Fragment code is use the getActivity method to get a reference to your Activity, and then the usual findViewById method to get a reference to your widget:

Source code for an example Android 'send email' function/method

Android FAQ: Can you share some source code for an Android send email method?

If you need a simple Android 'send email' function/method, this source code should do the trick for you:

Putting a menu item in the ActionBar - Android Honeycomb

With my usual apology of late that I don't have much time for writing these days, if you're working with Android Honeycomb (3.2) or newer, and want to put a menu item in the ActionBar (Action Bar) for an Activity, I hope this source code will help.

To put a menu item in the Action Bar, you'll need to edit these files:

Acer Iconia A100 - Turning off the blinking home button (light)

Acer Iconia A100 FAQ: How do I turn off the crazy blinking home button/light on the Acer Iconia?

The Iconia home button light blinks when you have a notification you haven't responded to, such as a new email message. To turn off the blinking light, look at the menu bar at the bottom of the screen, and just to the left of the time you'll see an icon indicating that you have some sort of notification. Tap on that icon, delete your notification(s), and the home button will stop blinking.

How to make a phone call from your Android app

I came across this Android phone dialer tip yesterday. If you want to make a phone call from an Android application, all you have to do is create a new Intent, either an Intent.ACTION_DIAL (to start the call) or Intent.ACTION_CALL (to place the call).

Here are the three lines of source code you need to get started:

Syndicate content