A less publicized feature of Android is the ability to share content between applications. We're going to use this feature to populate our List with our contacts' names and their current distance from our phone so we create an updateList method that we call after we've gotten our current location.
Use the ContentResolver to return a query that provides access to data shared using Content Providers. Queries are returned ascursors that provide access to the underlying data tables. The data we're interested in is accessed using the People content provider.
- Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null); startManagingCursor(c);
- int coordIdx = c.getColumnIndex(People.NOTES); int phoneIdx = c.getColumnIndex(People.PhonesColumns.NUMBER); int nameIdx = c.getColumnIndex(People.NAME);
- List
- String name = c.getString(nameIdx);
String coords = c.getString(coordIdx);
String phone = c.getString(phoneIdx);
... [ Process the lat/long from the coordinates ] ...
... [ Storing their location under variable loc ] ...
String distStr = String.valueOf(location.distanceTo(loc)/1000);
name = name + " (" + distStr + "km)";
listItems.add(name);
numbers.add("tel:" + phone);
- ArrayAdapter
No comments:
Post a Comment