I have tried to set mobile data. But it just worked for only 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, ClassNotFoundException, IllegalAccessException, 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;
}
But now I just want to launch that default mobile selection Dialog . If you have Any idea to launch that dialog let me know.. thanks in advance.
.
To get Dialog internet APN settings dial #107#8#2#3#. For Dialog MMS APN settings dial #107#8#2#2#. For Dialog streaming APN settings dial #107#8#2#4#.
To enter internet settings manuallyFind and tap Settings → Network & Internet → Mobile network. Tap Access Point Names (APN), then tap the plus (+) sign and enter the access point name. Tap Name and enter the name of the network profile that you want to create → OK. Tap APN and enter the access point name → OK.
Go to internet settings set USERNAME as dialog and APN as ppwap if postpaid set APN as dialogbb. Then change network mode to LTE and restart the device and check it. If not To check signal refer www.dialog.lk (coverage map) or contact dialog agent through 0777678678 WhatsApp number to get this done.
Multi SIM support is added in android lollipop 5.1 onwards only. Prior to that different phone manufacturers have their own custom implementation for supporting Multi SIM and respective settings. Hence if you are targeting for general solution it is not possible to achieve. Even on 5.1, there is no direct intent to launch this particular setting but using a hack you may achieve provided manufacturers should use only Google solution otherwise it will not work.
You have to start intent for settings like this.
startActivityForResult(new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS), 0);
'Note' There are also settings of WIFI and more .Explore it the much you want. like this
android.provider.Settings.ACTION_WIFI_SETTINGS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With