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
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.
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.
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.
Here is what you need to add to your manifest file
<uses-permission android:name="android.permission.ACCESS_FINE_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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With