2012-03-10 18 views

答えて

2
private void setMobileDataEnabled(Context context, boolean enabled) throws Exception{ 
    final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 
    Class conmanClass = null; 
    try { 
     conmanClass = Class.forName(conman.getClass().getName()); 
    } catch (ClassNotFoundException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    final Field iConnectivityManagerField = conmanClass.getDeclaredField("mService"); 
    iConnectivityManagerField.setAccessible(true); 
    final Object iConnectivityManager = iConnectivityManagerField.get(conman); 
    final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); 
    final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE); 
    setMobileDataEnabledMethod.setAccessible(true); 
    setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled); 
} 

は、無線LANのために行く

関連する問題