Enable/disable use data packet from android code
<p>I want to disable or enable use data packet in android device from my application from which I have used on code as below :</p>

<pre><code>try {
        Method dataConnSwitchmethod;
        Class telephonyManagerClass;
        Object ITelephonyStub;
        Class ITelephonyClass;

        TelephonyManager telephonyManager = (TelephonyManager) NetworkMonitorDemoAppActivity.this.getSystemService(Context.TELEPHONY_SERVICE);

        if (telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED) {
            isEnabled = true;
        } else {
            isEnabled = false;
        }

        telephonyManagerClass = Class.forName(telephonyManager.getClass().getName());
        Method getITelephonyMethod = telephonyManagerClass.getDeclaredMethod("getITelephony");
        getITelephonyMethod.setAccessible(true);
        ITelephonyStub = getITelephonyMethod.invoke(telephonyManager);
        ITelephonyClass = Class
                .forName(ITelephonyStub.getClass().getName());

        if (isEnabled) {
            dataConnSwitchmethod = ITelephonyClass.getDeclaredMethod("disableDataConnectivity");
        } else {
            dataConnSwitchmethod = ITelephonyClass.getDeclaredMethod("enableDataConnectivity");
        }
        dataConnSwitchmethod.setAccessible(true);
        dataConnSwitchmethod.invoke(ITelephonyStub);
    } catch (Exception e) {
        System.out.println("error is occured in uses data packet enable &amp; disable :-"+e.getMessage());
    }
</code></pre>

<p>But this code is not working fine. Can any my friend help me for this issue ?</p>
