Stack Overflow にある以下のコードを使用して、デバイスで GPS が有効か無効かを確認しました。
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 (Settings.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);
}
}
私のデバイス(Huawei G610)で問題なく動作し、問題はありません。次に、Samsung Galaxy Note を使用している友人にこのアプリケーションを渡したところ、GPS サービスが有効になっていないかどうかは通知されないとのことでした。
この関数は、GPS が有効になっていない場合に警告ダイアログをトリガーして、ユーザーに有効にするように求めるために使用されます。
彼のデバイスで動作しない理由がわかりません。ご協力をお願いします。一部のデバイスでは機能せず、一部のデバイスでは機能しない理由について尋ねています。
ありがとう。