Android Question Change Network operator with code

Discussion in 'Android Questions' started by walmo, Aug 31, 2018.

  1. walmo

    walmo Member Licensed User

    Please There must be a way to change the network operator on a rooted device.
    I found this code that use the TelephonyManager to change data state and it is working
    very nice , but i also need to change the network operator.

    Sub Process Globals
    Dim joData As JavaObject
    End Sub

    Sub ToggleData(dataState as Boolean)
    If joData.IsInitialized = False Then
    End If
    End Sub

    #If JAVA
    import android.content.Context;
    import android.os.Build;
    import android.telephony.SubscriptionManager;
    import android.telephony.TelephonyManager;
    import java.lang.reflect.Field;
    import java.lang.reflect.Method;

        Context context1;
        public void changeConnection(boolean enable) {
            context1 = this.getApplicationContext();
                StringBuilder command = new StringBuilder();
                command.append("su -c ");
                command.append("service call phone ");
                command.append(getTransactionCode() + " ");
                if (Build.VERSION.SDK_INT >= 22) {
                    SubscriptionManager manager = SubscriptionManager.from(context1);
                    int id = 0;
                    if (manager.getActiveSubscriptionInfoCount() > 0)
                        id = manager.getActiveSubscriptionInfoList().get(0).getSubscriptionId();
                    command.append("i32 ");
                    command.append(String.valueOf(id) + " ");
                command.append("i32 ");
            }catch(IOException e){
         //       ...
        private String getTransactionCode() {
            try {
                TelephonyManager telephonyManager = (TelephonyManager) context1.getSystemService(Context.TELEPHONY_SERVICE);
                Class<?> telephonyManagerClass = Class.forName(telephonyManager.getClass().getName());
                Method getITelephonyMethod = telephonyManagerClass.getDeclaredMethod("getITelephony");
                Object ITelephonyStub = getITelephonyMethod.invoke(telephonyManager);
                Class<?> ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName());
                Class<?> stub = ITelephonyClass.getDeclaringClass();
                Field field = stub.getDeclaredField("TRANSACTION_setDataEnabled");
                return String.valueOf(field.getInt(null));
            } catch (Exception e) {
                if (Build.VERSION.SDK_INT >= 22)
                    return "86";
                else if (Build.VERSION.SDK_INT == 21)
                    return "83";
            return "";
    #End If

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice