場所モード無効か手動かどうかをチェックすることができますし、無効にした場合示されているようにあなたがそれを有効にする設定を直接開くことができます。
public static boolean isLocationServicesAvailable(Context context) {
int locationMode = 0;
String locationProviders;
boolean isAvailable = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
isAvailable = (locationMode != Settings.Secure.LOCATION_MODE_OFF);
} else {
locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
isAvailable = !TextUtils.isEmpty(locationProviders);
}
// boolean coarsePermissionCheck = (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED);
// boolean finePermissionCheck = (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED);
return isAvailable;
}
openeningの設定を無効にした場合には:
if(!isLocationServicesAvailable(this)) {
// notify user
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("enabled");
dialog.setPositiveButton("open GPS", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(myIntent);
//get gps
}
});
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
// TODO Auto-generated method stub
}
});
dialog.show();
}
私は、インターネットとGPSを手動でチェックするのではなく、より一般的な解決策があることを期待していました。 – hsen
私はあなたが手動でそれをチェックしなければならないと思います。 –