Called: java.lang.SecurityException: gps location provider requires ACCESS_FINE_LOCATION permission

I have already installed permission. Why am I still getting this error?

Raised: java.lang.SecurityException: gps location provider requires ACCESS_FINE_LOCATION permission.

My manifestation:

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

My Activity code:

  public class LocationActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_location); if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()) .commit(); } } /** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { private LocationManager mLocationManager; public PlaceholderFragment() { } private final LocationListener locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { txtLat = (TextView) findViewById(R.id.textview1); txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude()); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_location, container, false); mLocationManager = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE); mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, locationListener); return rootView; } } } 
+5
source share
2 answers

What is your targetSdkVersion ?

In your apps targeting Android 6.0 (API level 23) or higher, be sure to check and request permissions at runtime. To determine whether permission has been granted to your application, call the new checkSelfPermission () method. To request permission, call the new requestPermissions () method. Even if your application is not designed for Android 6.0 (API level 23), you should check your application in the new permission model .: From the Android site

In Android 6.0 Marshmallow, the application will not receive permission during installation. Instead, the application should ask the user for permission one by one at runtime only if the target level of the application is 23 .

For an older version:
If the targetSdkVersion application is set to less than 23. It is assumed that the application has not yet been tested with the new permission system and will switch to the previous behavior: the user must accept all permissions during installation, and all of them will be granted after installation!

+10
source

The problem may be that you are putting permissions in front of application tags. Try adding permissions after the application tag i.ejust before the closing manifest tag.

-1
source

Source: https://habr.com/ru/post/1205754/


All Articles