I swear I've double checked permissions and restarted the emulator.
This is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxx.xxxx.gpsutility">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
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_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
</manifest>
This is the code that is the cause of the security exception (the last line):
protected void requestUpdates(long minTime, float minDistance) {
// Initialize result list.
mRecordedLocations = new ArrayList<Location>();
// Initialize location listener.
mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
if (mRecordedLocations.size() == 1) {
makeText("Received first location");
}
mRecordedLocations.add(location);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
};
// Request location updates.
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, mLocationListener);
}
The method is implemented inside a fragment and it is protected because I subclass the fragment in order to have easy access to gps in other fragments. Could this be an issue?