2012-09-17 39 views

回答

6

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

這是_Settings.Global.DATA_ROAMING_從API 17。 – lomza

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; 
    } 
} 
相關問題