Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android location manager permissions to be used

I have the following code in my android project:

locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
bestProvider = locationManager.getBestProvider(criteria, false);
Location currentLocation = locationManager.getLastKnownLocation(bestProvider);
location = currentLocation.getLatitude() + " " + currentLocation.getLongitude();
MyLocation.setText(location);

I am getting an provider == null error. what permissions do I need to use?

My android manifest file is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.DuckTag"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".DuckTagActivity"
              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>
</manifest>

Thank you

like image 323
Brahadeesh Avatar asked Aug 01 '11 14:08

Brahadeesh


People also ask

What is the main purpose of your app location permission?

You should never request location permissions from users for the sole purpose of advertising or analytics. Background location may only be used to provide features beneficial to the user and relevant to the core functionality of the app.

Should I remove permissions if app isn't used?

When you are no longer actively using an app, it's best to revoke any sensitive permission you may have granted it. Thankfully, on your Android phone or tablet, you don't have to manually go on about doing that.

Why does Google need location permission?

If Google Location Accuracy (also known as Google Location Services) is on, Google Location Accuracy can collect data to improve location-based services. Learn about Google Location Accuracy. You can get search results based on your phone's location, if your app and browser permissions allow it.


1 Answers

Here is what you need to add to your manifest file

GPS-based location

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

Network-based location

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

Previous posters are wrong, if you want to use both, then only ACCESS_FINE_LOCATION is required, as detailed here: http://developer.android.com/guide/topics/location/obtaining-user-location.html

Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.

like image 167
Kurru Avatar answered Oct 20 '22 09:10

Kurru