Check if 'Access to my location' is enabled - Android

后端 未结 5 727
无人共我
无人共我 2021-02-02 13:33

I have an android app that uses location. But I noticed that if users disable the \'Access to my location\' in Settings > Location access, nothing works anymore. How can I check

5条回答
  •  故里飘歌
    2021-02-02 14:19

    There are two ways to check location, 1-using GPS 2-using network provider its better to check both service are enabled or not.For that use this method :)

    public boolean checkServices(){
        //check location service
        LocationManager locationManager = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE);
        if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) &&
                locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
                return true;
        }
    }
    

提交回复
热议问题