Usar este código
boolean hasGps = pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
si ha incrustado hardware GPS para el dispositivo pero no está activada, utilice el siguiente bacalao que le permita de forma dinámica,
LocationManager manager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
if(!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//Ask the user to enable GPS
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Location Manager");
builder.setMessage("Would you like to enable GPS?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Launch settings, allowing user to make a change
Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(i);
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//No location service, no Activity
finish();
}
});
builder.create().show();
}
Puede llamar LocationManager.getAllProviders()
y compruebe si LocationManager.GPS_PROVIDER
está incluido en la lista.
else simplemente utiliza este código LocationManager.isProviderEnabled(String provider)
método.
si return false incluso en el caso si usted don `t tiene GPS en su dispositivo
Tengo un proveedor sin GPS, pero pm.hasSystemFeature (PackageManager.FEATURE_LOCATION_GPS); siempre devuelve True – skayred
ver la edición y se tratan – Karthi
LocationManager.isProviderEnabled (proveedor de cadena) return false para mi tableta, eso es cierto. Pero si tengo el GPS desactivado en la computadora de mano con soporte de GPS, también será falso. Necesito verificar la disponibilidad del hardware, estado no activado-deshabilitado – skayred