简体   繁体   中英

android mobile data/3G

how can I disable and enable the mobile data(3G) on Android?

I read that I need to use the connectivity manager. However, I still don't understand how I can enable and disable the mobile data?

I found this, however, it doesn't work for me,

Can anyone explain me what can I do to turn on and off the mobile data?

TelephonyManager telephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
switch (telephonyManager.getDataState()) {
        case TelephonyManager.DATA_CONNECTED:
            setMobileDataEnabledMethod.invoke(iConnectivityManager, false);
            break;
        case TelephonyManager.DATA_DISCONNECTED:
            setMobileDataEnabledMethod.invoke(iConnectivityManager, true);
            break;
        }

How to disable Mobile Data on Android

Against which api level are you developing? Logcat as Siddharth suggest ... Too less informations top help you appropriate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM