당신은 여부를 확인할 수 있습 GPS 를 사용하고 메시지가 표시되지 않은 경우 사용
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//here do what you want when the GPS service is enabled
Toast.makeText(MainActivity.this, "is enable", Toast.LENGTH_SHORT).show();
} else {
MaterialAlertDialogBuilder locationDialog = new MaterialAlertDialogBuilder(MainActivity.this);
locationDialog.setTitle("Attention");
locationDialog.setMessage("Location settings must be enabled from the settings to use the application");
locationDialog.setCancelable(false);
locationDialog.setPositiveButton("Open settings", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
});
locationDialog.create().show();
}
}
}