you can check your provider is null and ask the user to go to system settings to enable GPS
here is the code
locationManager = (LocationManager) getSystemService(context);
criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setSpeedRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_HIGH);
provider = locationManager.getBestProvider(criteria, true);
if(provider==null){
new AlertDialog.Builder(this)
.setTitle("Location Settings")
.setMessage("Application needs your location,do you want to go to\n" +
"system settings to enable your location source?")
.setIcon(android.R.drawable.ic_menu_mapmode)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try{
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}catch(Exception e){
e.printStackTrace();
}
}})
.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
LocationBasedServicesV1.this.finish();
}
})
.show();
}