Adjusting the Permissions Level

The first step in working with the Android Location-Based API is to adjust the permissions level. Using the Android Location-Based API itself does not require any specific permission, but using the Android Location-Based API to access location information on the GPS does.

There are two ways you can set the permission from Eclipse. The first is through the Android Manifest Permissions wizard, which you used in Chapter 7. In Eclipse, double-click AndroidManifest.xml to open the Android Manifest Overview window. Click the Permission link and, using the same method described in Chapter 7, add the ACCESS_GPS and ACCESS_LOCATION Uses Permission as shown in the following illustration.

The second way you can add the permission values to your Activity is to edit AndroidManifest.xml manually. You would need to add the following lines to AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_GPS"> </uses-permission>

<uses-permission android:name="android.permission.ACCESS_LOCATION"> </uses-permission>

The syntax here is to add the permission name within the <uses-permission> tag.

When you have finished adding the permissions, your AndroidManifest.xml file should look like the following code snippet. This code should look pretty familiar by now. You are using just one Activity in the Intent Filter, and a pair of permissions.

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android= package="android_programmers_guide.AndroidLBS"> <application android:icon="@drawable/icon"> <activity android:name=".AndroidLBS" android:label="@string/app_name"> <intent-filter>

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>

<uses-permission android:name="android.permission.ACCESS_GPS"> </uses-permission><uses-permission android:name="android.permission.ACCESS_LOCATION"> </uses-permission></manifest>

0 0

Post a comment