6

ユーザーがデータローミングを有効/無効にしているかどうかを確認しようとしています。これまでに見つけたのは、TelephonyManager.isNetworkRoaming() と NetworkInfo.isRoaming() を使用して、ユーザーが現在ローミング中であるかどうかを確認できることだけですが、それらは私が必要としているものではありません。

4

4 に答える 4

8

Nippeyの回答に基づくと、私にとって実際に機能したコードは次のとおりです。

public Boolean isDataRoamingEnabled(Context context) {
    try {
        // return true or false if data roaming is enabled or not
        return Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.DATA_ROAMING) == 1;
    } 
    catch (SettingNotFoundException e) {
        // return null if no such settings exist (device with no radio data ?) 
        return null;
    }
}
于 2013-02-21T08:27:02.920 に答える
4
public static final Boolean isDataRoamingEnabled(final Context application_context)
{
    try
    {
        if (VERSION.SDK_INT < 17)
        {
            return (Settings.System.getInt(application_context.getContentResolver(), Settings.Secure.DATA_ROAMING, 0) == 1);
        }

        return (Settings.Global.getInt(application_context.getContentResolver(), Settings.Global.DATA_ROAMING, 0) == 1);
    } 
    catch (Exception exception)
    {
        return false;
    }
}
于 2015-12-10T10:11:34.230 に答える
4

Roaming-Switch の状態は、次の方法でリクエストできます。

ContentResolver cr = ContentResolver(getCurrentContext());
Settings.Secure.getInt(cr, Settings.Secure.DATA_ROAMING);

参照: http://developer.android.com/reference/android/provider/Settings.Secure.html#DATA_ROAMING

于 2012-09-18T09:21:21.053 に答える
2

API の廃止を考慮して関数を更新しました。現在は次のように置き換えられています: http://developer.android.com/reference/android/provider/Settings.Global.html#DATA_ROAMING

public static boolean IsDataRoamingEnabled(Context context) {
    try {
        // return true or false if data roaming is enabled or not
        return Settings.Global.getInt(context.getContentResolver(), Settings.Global.DATA_ROAMING) == 1;
    } 
    catch (SettingNotFoundException e) {
        return false;
    }
}
于 2014-11-18T20:26:24.347 に答える