In my app, I need GPS to locate the user. I wish my app provide following kinds of result.
1.The current location.(Success)
2.Failed to get current location because of device error or something else. (Failed)
3.The user refused the permission. (Permission denied)
I use LocationManager to do the job.
locationManager = (LocationManager)mActivity.getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
If the permission is denied, the location will be null.
But I don't know what the location will be if the function failed. And I 'm not sure whether that location is null and user refuse to open GPS are equal.
With the following code, I might know whether the permission is added in the AndroidManifest.xml. But I can't get the information I need.
boolean getLocationOn = (PackageManager.PERMISSION_GRANTED ==
pm.checkPermission("android.permission.ACCESS_FINE_LOCATION", "my_package"));