我试图设置移动数据.但它只适用于SIM卡1.
public static void setMobileData(Context context,boolean isEnabled) throws NoSuchFieldException,ClassNotFoundException,IllegalAccessException,NoSuchMethodException,InvocationTargetException { ConnectivityManager conman = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); @SuppressWarnings("rawtypes") final Class conmanClass = Class.forName(conman.getClass().getName()); final Field iConnectivityManagerField = conmanClass.getDeclaredField("mService"); iConnectivityManagerField.setAccessible(true); final Object iConnectivityManager = iConnectivityManagerField.get(conman); final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); Class[] cArg = new Class[2]; cArg[0] = String.class; cArg[1] = Boolean.TYPE; Method setMobileDataEnabledMethod; setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled",cArg); Object[] pArg = new Object[2]; pArg[0] = context.getPackageName(); pArg[1] = isEnabled; setMobileDataEnabledMethod.setAccessible(true); setMobileDataEnabledMethod.invoke(iConnectivityManager,pArg); } public static void setMobileData2(Context context,boolean isEnabled) throws NoSuchMethodException,NoSuchFieldException,InvocationTargetException { final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final Class conmanClass = Class.forName(conman.getClass().getName()); 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,isEnabled); } public static boolean setMobileData3(Context context,boolean isEnable) { boolean mobileDataAllowed = Settings.Secure.putInt(context.getContentResolver(),"mobile_data",isEnable?1:0); return mobileDataAllowed; }
但是现在我只想启动默认的移动选择对话框.如果你有任何想法,启动该对话框让我知道..谢谢提前.
.