Android Programming Tutorials

(Romina) #1

TUTORIAL 21


Posts On Location


In this tutorial, we will integrate location tracking, such that we can


optionally embed our location in our status updates following the


Twittervision convention.


Step-By-Step Instructions........................................................................


First, you need to have completed the previous tutorial. If you are


beginning the tutorials here, or if you wish to not use your existing work,


you can download a ZIP file with all of the tutorial results, and you can copy


the 20-Notifications edition of Patchy to use as a starting point.


Step #1: Get the LocationManager....................................................


First, we need to arrange to have access to Android location services


through the LocationManager.


This requires a permission, either ACCESS_COARSE_LOCATION or


ACCESS_FINE_LOCATION. Since the emulator simulates GPS, which needs


ACCESS_FINE_LOCATION, modify Patchy/AndroidManifest.xml to add this


permission:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="apt.tutorial.two"
android:versionCode="1"

227
Free download pdf