Caused by: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission -
i set permission why still error: caused by: java.lang.securityexception: "gps" location provider requires access_fine_location permission.
my manifest.xml file:
<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" /> 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(); } } /** * placeholder fragment containing 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); homecoming rootview; } } }
what targetsdkversion?
on apps target android 6.0 (api level 23) or higher, create sure check , request permissions @ runtime. determine if app has been granted permission, phone call new checkselfpermission() method. request permission, phone call new requestpermissions() method. if app not targeting android 6.0 (api level 23), should test app under new permissions model. : from android site
in android 6.0 marshmallow, application not granted permission @ installation time. instead, application has inquire user permission one-by-one @ runtime only if application target level 23.
for older version: if application's targetsdkversion set less 23. assumed application not tested new permission scheme yet , switch same old behavior: user has take every single permission @ install time , granted 1 time installed !
location
No comments:
Post a Comment