Cover by Marko Gargenta

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Updating Yamba to Use the Location Service

The WhereAmI application was a small standalone test to make sure we can get location information. Now we’ll incorporate location information into our larger Yamba app.

Updating Our Preferences

First, the user might not want to broadcast her location to the world, so we should ask. A good place to ask would be the Preferences. This time around, we’ll use a ListPreference property. This is somewhat different from the EditTextPreferences we’ve seen before in Chapter 7, in that it requires a list of items. In fact, it requires two lists: one to display and one to use for actual values.

So we’ll add a couple of strings to our strings.xml file and create two new string resources: one to represent names of our location providers in a form friendly to human readers and the other to represent their values. To do that, we’ll add the following to our strings.xml file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  ...
  <string-array name="providers">
    <item>None, please</item>
    <item>GPS via satellites!</item>
    <item>Mobile Network will do</item>
  </string-array>

  <string-array name="providerValues">
    <item>NONE</item>
    <item>gps</item>
    <item>network</item>
  </string-array>
</resources>

Notice that both string arrays have the same number of elements. They basically represent name-value pairs and match each other.

Now that we have the names and values for our location providers, we can update prefs.xml with that information, as shown in Example 13-6.

Example 13-6. Updated ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required