Java Code Examples for android.telephony.TelephonyManager#getDataState()

The following examples show how to use android.telephony.TelephonyManager#getDataState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Device.java    From AIMSICDL with GNU General Public License v3.0 6 votes vote down vote up
String getDataState(TelephonyManager tm) {
    int state = tm.getDataState();
    mDataState = "undef";
    mDataStateShort = "un";
    switch (state) {
        case TelephonyManager.DATA_DISCONNECTED:
            mDataState = "Disconnected";
            mDataStateShort = "Di";
            break;
        case TelephonyManager.DATA_CONNECTING:
            mDataState = "Connecting";
            mDataStateShort = "Ct";
            break;
        case TelephonyManager.DATA_CONNECTED:
            mDataState = "Connected";
            mDataStateShort = "Cd";
            break;
        case TelephonyManager.DATA_SUSPENDED:
            mDataState = "Suspended";
            mDataStateShort = "Su";
            break;
    }

    return mDataState;
}
 
Example 2
Source File: Util.java    From ki4a with Apache License 2.0 6 votes vote down vote up
protected static void prepareInterfaces(WifiManager wifiManager, TelephonyManager telephonyManager)
{
    // If wifi is On, we need to turn it off first
    if(wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(false);
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    if(ki4aService.preferences.getBoolean("cellular_switch",true) &&
        ki4aService.preferences.getBoolean("airplane_switch",true))
    {
        // If data connection is not connected, we'll try to bring it up
        if (telephonyManager.getDataState() != telephonyManager.DATA_CONNECTED &&
                telephonyManager.getDataState() != telephonyManager.DATA_CONNECTING)
            Util.refreshMobileData();
    }
}
 
Example 3
Source File: Network.java    From batteryhub with Apache License 2.0 6 votes vote down vote up
public static String getDataState(Context context) {
    TelephonyManager manager = (TelephonyManager)
            context.getSystemService(Context.TELEPHONY_SERVICE);

    int dataState = manager.getDataState();

    switch (dataState) {
        case TelephonyManager.DATA_CONNECTED:
            return DATA_CONNECTED;
        case TelephonyManager.DATA_CONNECTING:
            return DATA_CONNECTING;
        case TelephonyManager.DATA_DISCONNECTED:
            return DATA_DISCONNECTED;
        default:
            return DATA_SUSPENDED;
    }
}
 
Example 4
Source File: NetworkUtil.java    From NIM_Android_UIKit with MIT License 6 votes vote down vote up
public static boolean getNetworkConnectionStatus(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (manager == null) {
        return false;
    }

    NetworkInfo info = manager.getActiveNetworkInfo();
    if (info == null) {
        return false;
    }

    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null) {
        return false;
    }

    if ((tm.getDataState() == TelephonyManager.DATA_CONNECTED || tm.getDataState() == TelephonyManager.DATA_ACTIVITY_NONE)
            && info.isAvailable()) {
        return true;
    } else {
        return false;
    }
}
 
Example 5
Source File: SanaUtil.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns true if the phone has telphony or wifi service
 *
 * @param c - The current context
 * @return true if Android has either a wifi or cellular connection active
 */
public static boolean checkConnection(Context c) {
    try {
        TelephonyManager telMan = (TelephonyManager) c.getSystemService(
                Context.TELEPHONY_SERVICE);
        WifiManager wifiMan = (WifiManager) c.getSystemService(
                Context.WIFI_SERVICE);

        if (telMan != null && wifiMan != null) {
            int dataState = telMan.getDataState();
            if (dataState == TelephonyManager.DATA_CONNECTED ||
                    (wifiMan.isWifiEnabled() && wifiMan.pingSupplicant()))
                return true;
        }

        return false;
    } catch (Exception e) {
        Log.e(TAG, "Exception in checkConnection(): " + e.toString());
        return false;
    }
}
 
Example 6
Source File: PhoneUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取 高通 神机的双卡 IMSI、IMSI 信息
 * @return 高通 神机的双卡 IMSI、IMSI 信息
 */
public static TeleInfo getQualcommTeleInfo() {
    TeleInfo teleInfo = new TeleInfo();
    try {
        TelephonyManager telephonyManager = AppUtils.getTelephonyManager();
        Class<?> simTMclass = Class.forName("android.telephony.MSimTelephonyManager");
        @SuppressWarnings("WrongConstant")
        Object sim = AppUtils.getSystemService("phone_msim");
        int simId_1 = 0;
        int simId_2 = 1;

        Method getSubscriberId = simTMclass.getMethod("getSubscriberId", int.class);
        String imsi_1 = (String) getSubscriberId.invoke(sim, simId_1);
        String imsi_2 = (String) getSubscriberId.invoke(sim, simId_2);
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imsi_2 = imsi_2;

        Method getDeviceId = simTMclass.getMethod("getDeviceId", int.class);
        String imei_1 = (String) getDeviceId.invoke(sim, simId_1);
        String imei_2 = (String) getDeviceId.invoke(sim, simId_2);
        teleInfo.imei_1 = imei_1;
        teleInfo.imei_2 = imei_2;

        Method getDataState = simTMclass.getMethod("getDataState");
        int phoneType_1 = telephonyManager.getDataState();
        int phoneType_2 = (Integer) getDataState.invoke(sim);
        teleInfo.phoneType_1 = phoneType_1;
        teleInfo.phoneType_2 = phoneType_2;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getQualcommTeleInfo");
    }
    return teleInfo;
}
 
Example 7
Source File: TelephoneUtil.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * Qualcomm Phone.
 * 获取 高通 神机的双卡 IMSI、IMSI 信息
 */
public static TeleInfo getQualcommTeleInfo(Context context) {

    try {
        TeleInfo teleInfo = new TeleInfo();
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Class<?> simTMclass = Class.forName("android.telephony.MSimTelephonyManager");
        Object sim = context.getSystemService(Context.TELEPHONY_SERVICE);
        int simId_1 = 0;
        int simId_2 = 1;

        Method getSubscriberId = simTMclass.getMethod("getSubscriberId", int.class);
        String imsi_1 = (String) getSubscriberId.invoke(sim, simId_1);
        String imsi_2 = (String) getSubscriberId.invoke(sim, simId_2);
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imsi_2 = imsi_2;

        Method getDeviceId = simTMclass.getMethod("getDeviceId", int.class);
        String imei_1 = (String) getDeviceId.invoke(sim, simId_1);
        String imei_2 = (String) getDeviceId.invoke(sim, simId_2);
        teleInfo.imei_1 = imei_1;
        teleInfo.imei_2 = imei_2;

        Method getDataState = simTMclass.getMethod("getDataState");
        int phoneType_1 = tm.getDataState();
        int phoneType_2 = (Integer) getDataState.invoke(sim);
        teleInfo.phoneType_1 = phoneType_1;
        teleInfo.phoneType_2 = phoneType_2;

        Log.i(TAG, "Qualcomm: " + teleInfo);
        return teleInfo;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

}
 
Example 8
Source File: TelephoneUtil.java    From zone-sdk with MIT License 5 votes vote down vote up
/**
 * Qualcomm Phone.
 * 获取 高通 神机的双卡 IMSI、IMSI 信息
 */
@SuppressWarnings("ALL")
public static TeleInfo getQualcommTeleInfo(Context context) {
    TeleInfo teleInfo = new TeleInfo();
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Class<?> simTMclass = Class.forName("android.telephony.MSimTelephonyManager");
        Object sim = context.getSystemService("phone_msim");
        int simId_1 = 0;
        int simId_2 = 1;

        Method getSubscriberId = simTMclass.getMethod("getSubscriberId", int.class);
        String imsi_1 = (String) getSubscriberId.invoke(sim, simId_1);
        String imsi_2 = (String) getSubscriberId.invoke(sim, simId_2);
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imsi_2 = imsi_2;

        Method getDeviceId = simTMclass.getMethod("getDeviceId", int.class);
        String imei_1 = (String) getDeviceId.invoke(sim, simId_1);
        String imei_2 = (String) getDeviceId.invoke(sim, simId_2);
        teleInfo.imei_1 = imei_1;
        teleInfo.imei_2 = imei_2;

        Method getDataState = simTMclass.getMethod("getDataState");
        int phoneType_1 = tm.getDataState();
        int phoneType_2 = (Integer) getDataState.invoke(sim);
        teleInfo.phoneType_1 = phoneType_1;
        teleInfo.phoneType_2 = phoneType_2;
    } catch (Exception e) {
        e.printStackTrace();
    }
    LogZSDK.INSTANCE.i("Qualcomm: " + teleInfo);
    return teleInfo;
}
 
Example 9
Source File: TelephoneUtil.java    From android-common with Apache License 2.0 5 votes vote down vote up
/**
 * Qualcomm Phone.
 * 获取 高通 神机的双卡 IMSI、IMSI 信息
 */
public static TeleInfo getQualcommTeleInfo(Context context) {
    TeleInfo teleInfo = new TeleInfo();
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Class<?> simTMclass = Class.forName("android.telephony.MSimTelephonyManager");
        Object sim = context.getSystemService("phone_msim");
        int simId_1 = 0;
        int simId_2 = 1;

        Method getSubscriberId = simTMclass.getMethod("getSubscriberId", int.class);
        String imsi_1 = (String) getSubscriberId.invoke(sim, simId_1);
        String imsi_2 = (String) getSubscriberId.invoke(sim, simId_2);
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imsi_2 = imsi_2;

        Method getDeviceId = simTMclass.getMethod("getDeviceId", int.class);
        String imei_1 = (String) getDeviceId.invoke(sim, simId_1);
        String imei_2 = (String) getDeviceId.invoke(sim, simId_2);
        teleInfo.imei_1 = imei_1;
        teleInfo.imei_2 = imei_2;

        Method getDataState = simTMclass.getMethod("getDataState");
        int phoneType_1 = tm.getDataState();
        int phoneType_2 = (Integer) getDataState.invoke(sim);
        teleInfo.phoneType_1 = phoneType_1;
        teleInfo.phoneType_2 = phoneType_2;
    } catch (Exception e) {
        e.printStackTrace();
    }
    Log.i(TAG, "Qualcomm: " + teleInfo);
    return teleInfo;
}