2012-09-17 2 views

답변

4

당신은을 통해 로밍 스위치의 상태를 요청할 수 있습니다

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

참조 : Nippey의 답변에 따라

6

http://developer.android.com/reference/android/provider/Settings.Secure.html#DATA_ROAMING, 나를 위해 일한 코드의 실제 부분은 다음과 같습니다

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; 
    } 
} 
+0

: 지금으로 대체됩니다. – lomza

2

API 지원 중단을 설명하기 위해 함수를 업데이트했습니다. 그것은 API 17 _Settings.Global.DATA_ROAMING_있어 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; 
    } 
} 
2
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); 
     } 
     else 
     { 
      return (Settings.Global.getInt(APPLICATION_CONTEXT.getContentResolver(), Settings.Global.DATA_ROAMING, 0) == 1); 
     } 
    } 
    catch (Exception exception) 
    { 
     return false; 
    } 
} 
관련 문제