android - error permision ACCESS_FIND_LOCATION -
i'm using permission access_fine_location
when run.error:requires access_fine_location permission
why?
thanks in advance.
<uses-permission android:name="android.permission.access_fine_location"/>
access_fine_location
, access_coarse_location
both permission required when trying location add both permission in manifest file if targeting android 6.0 , above add runtime permsiion below code
string permission = android.manifest.permission.access_fine_location; if (activitycompat.checkselfpermission(searchcityclass.this, permission) != packagemanager.permission_granted && activitycompat. checkselfpermission(searchcityclass.this, android.manifest.permission.access_coarse_location) != packagemanager.permission_granted) { activitycompat.requestpermissions(searchcityclass.this, new string[] {permission}, permission_gps_code); }
now handle permisiion result
@override public void onrequestpermissionsresult(int requestcode, @nonnull string[] permissions, @nonnull int[] grantresults) { super.onrequestpermissionsresult(requestcode, permissions, grantresults); if (requestcode == permission_gps_code) { if (grantresults[0] == packagemanager.permission_granted) { toast.maketext(this, "location_permission_granted ", toast.length_short).show(); } else { toast.maketext(this, "location_permission_not_granted ", toast.length_short).show(); } } }
wiki
Comments
Post a Comment