Android API Tutorial

Tutorial | Download | Usage

How to build a social geotagging service on Android in 5 minutes

This tutorial assumes you have installed the Android SDK, Eclipse and the Android plugin for Eclipse.
The tutorial sample source code is available in the api package under the samples/wiki directory. It was
tested with Android SDK 2.1 but should work with anything beyond SDK 1.5.
The tutorial comprises the following steps

  1. Create a new Android project.
  2. Change the build path to include the external jar gloecore.jar
  3. Copy all the files in the gloecore.zip file into the res directory of the project
  4. Modify the Android manifest file to include gloeapi dialogs
  5. Subclass the Main Dialog
  6. Subclass the Recommendation Dialog
  7. Test

Before you start with the first step download and unzip the contents of the gloeapi-1.0.0.zip file to a
directory of your choice.

Step 1: Create a new Android project

In Eclipse:

  • File->New-> Other…->Android:Android Project
  • Click Next
  • Fill out Project name, application name, package name, and activity name.

Step 2: Change the build path to include the gloe api library

  • Right click on the newly created project name in the Package Explorer.
  • Select Properties.
  • In the Properties dialog, select Build path and click on Add external Jar.
  • Locate and select the file gloecore.jar in the directory where you unpacked the gloeapi zip file.

Step 3: Copy the xml resource files into your project

  • Right click on the res directory under your project in the Package explorer.
  • Choose Import->General: File System
  • In the “From directory “ field specify or browse to the res directory located in the directory where you
  • unpacked the gloeapi.zip file.
  • Make sure that the Into folder specifies the res directory under your project . Click Finish.

Step 4: Modify the Android manifest file to include gloeapi dialogs

Add the following code snippet into your application scope in the AndriodManifest.xml file of your
project:

<activity android:name="com.hp.hpl.gloe.ChannelDialog" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.hp.hpl.gloe.SettingsDialog" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.hp.hpl.gloe.WebDialog" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.hp.hpl.gloe.FriendsDialog" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.hp.hpl.gloe.RegistrationDialog" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.hp.hpl.gloe.LoginDialog" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.hp.hpl.gloe.UsersDialog" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" />

Add the following code snippet into your manifest scope in the AndriodManifest.xml file of your project:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Step 5: Subclass the Main Dialog

In the Activity java source file you specified in Step 1 add the following in the class scope

static {
try {
GloeInit.init(MainWikiDialog.class,RecWikiDialog.class,R.class);
} catch (Exception e) {
Log.e("MainWikiDialog", "Init Failed", e);
}
initOptions("Wikipedia channel", "Add Wikipedia page", "wikipedia", "Geo Wiki v1.0.0");
}

The first argument to the init function is the class we are constructing in this step. The second argument
is the class we will build in the next step. The arguments to the initOptions function are: UI text for
channels, UI text for content creation, HP Gloe channel name, and application name.
Now override the function actionCallback to create the content you want to geotag. When done call the
recommend(url,title,channel) function to add the geomapping to HP Gloe.

Step 6: Subclass the Recommendation Dialog

  • Create a java class that extends RecommendationDialog
  • Override the method clickRec(RecInfo rec) to display or recommend a recommendation that the user selected.
  • Also add the class to the android manifest in the application scope:
<activity android:name=".RecWikiDialog" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" />

At this point the project should build without errors and you should be ready to test it in the emulator or
on a device.

Step 7: Test

  • Right click on your project in the Package Explorer and select Run As… Android application.

Final Comments

The app you just built has Gloe recommendation, discovery and channel browsing, as well as GPS
sensing, Geocoding, user account management, friends management, and facebook integration already
built-in to speed up testing of new geotagging ideas built on top of HP Gloe’s social geotagging service.
In addition to the Wikipedia sample, the HP Gloe (general channel browsing/recommendation, map and
AR views, Android browser tagging integration), Geo Poll (geography based polls), Geo Fan (geography
based fan clubs), Geo Sound (geo-based sound recording and discovery) applications on the Android
market have also been built using this library.