Posts Tagged: API

Jun 11

Android Port of the CloudMade API

If you are looking for a way to implement location based services within your android application without using the web services of Google, you might be interested in the CloudMade web services. These web services provide functions like geocoding, searching for objects which are close to a given coordinate, retrieving map tiles as images and even to create a full route from a start point via several transit points to an end point.

To provide these services, CloudMade relies on the collaborative OpenStreetMap (OSM) project which follows the same principles as Wikipedia to create a free map.

To ensure an easy usage of the web services, CloudMade provides several libraries for the iPhone and other programming languages. The provided Java API is using an old implementation of the Apache HTTP Client which makes it unusable for Android devices. That’s why I’ve created a port of the lightweight CloudMade Java API which can be used on android devices. Continue reading →

Jun 11

A Generic ListView and Spinner Adapter for Java Collections

In this post I will introduce a library which you can use to display elements from any java.util.Collection (e.g. LinkedList, ArrayList, HashSet, Queue, Stack, TreeSet,…) within a ListView or a Spinner. It’s even possible to use this library to implement any layout you want for your entries (e.g. a multi-line entry, an entry with including an image, etc…).

So this library is a very generic approach to display various data sets with custom layouts in a Spinner or a ListView. Continue reading →

May 11

Playing Animations in Android

If you want to add an animation to your app the first thing you think about is to use animated gifs. But when you perform some research on how to use animated gifs in android you will find out that android does not support this file type. Instead android will always just display one static frame of the animation. But android provides two powerful mechanisms which allow developers to create various types of animations. One way is to use tweened animations where you can define transformation operations such as acceleration, alpha, rotation, scaling, position, etc.  on your objects. The other possibility is to use a frame-by-frame mechanism where it’s possible to define different drawable resources and time intervals in which these resources will be displayed. In this blog post I want to give an introduction on how this frame by frame animation can be implemented in android.
Continue reading →

May 11

Using self-defined Parcelable objects during an Android AIDL RPC / IPC call

In my previous post “Using the Android Interface Definition Language (AIDL) to make a Remote Procedure Call (RPC) in Android” I’ve explained the basics on how inter-process communication can be implemented in Android. Now we will take a look at a specialized field in this area: Using Parcelables as parameters of an AIDL method.
As described in the previous post it is possible to either use primitive java types within a remote method signature or any class which implements the android.os.Parcelable interface. Using this interface it is possible to define arbitrarily complex data types which can be used as parameters or return values of methods during a remote method call.
I’ve created a modified version of the first example app to give you a basic example which relies on a Parcelable object as a method return value. Continue reading →

Apr 11

Using the Android Interface Definition Language (AIDL) to make a Remote Procedure Call (RPC) in Android

There are different ways to communicate with a Service. A commonly used approach is to use Intents where the Service can respond according to the intent action. This is easily implemented but if the Service is providing many different operations the resulting code might become complex which will result in a hardly maintainable code. Furthermore, when using Intents the developer always has to take care of adding the parameters to the intent and after the result intent was received the result-parameters have to be retrieved from the intent. This will result in an increased programming overhead within the client each time a remote functionality is called which can lead to error-prone code. To avoid these disadvantages you can use the built-in Remote Procedure Call (RPC) mechanism of Android. To demonstrate the use of RPCs in Android I’ve created a basic example. This example consists of two apps where the first contains a Service and the second an Activity. The Activity will connect to the Service using the Android RPC mechanism and will query a String from that Service. Continue reading →

Apr 11

Using Android Activities and Services in multiple Projects

When developing Apps for the Android OS you might end up in the situation where you have common Activities or Services which could be reused in multiple Apps with just a little modification. As you don’t want to copy these classes into every single project – which would lead to a hardly maintainable code – you would seek a way to reference the source of these classes from multiple projects. For non-android applications an approach for this problem would be to break up the code into multiple libraries so that the required functionality can be referenced from multiple projects. As long as you are not interacting with external resources this attempt is also possible in Android projects (build a jar and reference it from the projects). But if you are using external resources these classes can’t be used within a library. This is caused by the fact that the Android SDK won’t generate matching ids within the “R” class for external resources which are included in a referenced jar file. In this post I want to show you different solutions for this problem which can avoid the necessity to copy the source code into the projects. Continue reading →

Mar 11

Using custom layouts for “Spinner” or “ListView” entries in Android

Today we are going to take a look at custom entries for a Spinner or ListView. Android allows the developers to create custom layouts for the entries in a Spinner or ListView. Using this mechanism it’s possible to implement highly customized designs for the default GUI elements such as the spinner. For example it’s possible to implement a spinner with entries consisting of an image and of multiple lines of text. In this post I will explain the three steps required to implement this functionality using the Query Contacts App from my previous post. In this App I’ve implemented a Spinner with custom entries to display the contact photo together with the contact name embedded in a single entry. Furthermore each element of the ListView which is used to display the details of the contact contains two lines of text. Continue reading →

Mar 11

Working with the “ContactsContract” to query contacts in Android

When I was looking at the official example on the Google Android Developers site for accessing content providers in Android ( I found an outdated example to query contacts which is using deprecated fields in the Android API. As I’ve seen quite some developers who are still relying on that deprecated example to implement their functionality even when using the newer API levels I’ve decided to post an example which is using the new way suggested in the Android API.

Query Contacts AppTo demonstrate the features of the new API the example App is querying all available contacts on the phone and additionally commonly used information from the contacts content provider such as the name, phone numbers, email addresses and of course the photo. Continue reading →