Tag: gprs

以编程方式在android中启用/禁用数据连接

我想以编程方式启用/禁用数据连接。 我已经使用了下面的代码: void enableInternet(boolean yes) { ConnectivityManager iMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); Method iMthd = null; try { iMthd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class); } catch (Exception e) { } iMthd.setAccessible(false); if(yes) { try { iMthd.invoke(iMgr, true); Toast.makeText(getApplicationContext(), "Data connection Enabled", Toast.LENGTH_SHORT).show(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block dataButton.setChecked(false); Toast.makeText(getApplicationContext(), "IllegalArgumentException", Toast.LENGTH_SHORT).show(); } catch (IllegalAccessException […]