You can check if google play services are available. Follow the instructions here: https://developer.android.com/training/location/retrieve-current.html
GetLastLocation () may return null even if Google Play location services are enabled. For example, immediately after their repeated inclusion. However, you can then send your user to the Google Play Services Location Settings using the following destination:
Intent settings = new Intent("com.google.android.gms.location.settings.GOOGLE_LOCATION_SETTINGS"); startActivity(settings);
Finally, you can also check if Android location services are enabled:
public static boolean isLocationEnabled(Context context) { int locationMode = 0; String locationProviders; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ try { locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); } catch (SettingNotFoundException e) { e.printStackTrace(); } return locationMode != Settings.Secure.LOCATION_MODE_OFF; }else{ locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); return !TextUtils.isEmpty(locationProviders); } }
source share