Example usage for android.telephony TelephonyManager getNetworkCountryIso

List of usage examples for android.telephony TelephonyManager getNetworkCountryIso

Introduction

In this page you can find the example usage for android.telephony TelephonyManager getNetworkCountryIso.

Prototype

public String getNetworkCountryIso() 

Source Link

Document

Returns the ISO-3166 country code equivalent of the MCC (Mobile Country Code) of the current registered operator or the cell nearby, if available.

Usage

From source file:android_network.hetnet.vpn_service.Util.java

public static String getGeneralInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append(String.format("Interactive %B\r\n", isInteractive(context)));
    sb.append(String.format("Connected %B\r\n", isConnected(context)));
    sb.append(String.format("WiFi %B\r\n", isWifiActive(context)));
    sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context)));
    sb.append(String.format("Roaming %B\r\n", isRoaming(context)));

    if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
        sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(),
                tm.getSimOperator()));//  www. j a va  2s.c o m
    if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN)
        sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName(),
                tm.getNetworkOperator()));

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        sb.append(String.format("Battery optimizing %B\r\n", batteryOptimizing(context)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        sb.append(String.format("Data saving %B\r\n", dataSaving(context)));

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}

From source file:com.yozio.android.YozioHelper.java

private void setCarrierMobileAndDeviceInfo() {
    SharedPreferences settings = context.getSharedPreferences("yozioPreferences", 0);

    try {// www  .  j  ava2 s .  c o  m
        TelephonyManager telephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        carrierName = telephonyManager.getNetworkOperatorName();
        carrierCountryCode = telephonyManager.getNetworkCountryIso();

        if (telephonyManager.getNetworkOperator() != null
                && (telephonyManager.getNetworkOperator().length() == 5
                        || telephonyManager.getNetworkOperator().length() == 6)) {
            mobileCountryCode = telephonyManager.getNetworkOperator().substring(0, 3);
            mobileNetworkCode = telephonyManager.getNetworkOperator().substring(3);
        }

        deviceId = telephonyManager.getDeviceId();

        if (!isValidDeviceId(deviceId)) {
            // Fetch the emulator device ID from the preferences
            deviceId = settings.getString("emulatorDeviceId", null);
        }

        if (!isValidDeviceId(deviceId)) {
            StringBuffer buff = new StringBuffer();
            buff.append("emulator");

            String chars = "1234567890abcdefghijklmnopqrstuvw";
            int ccLength = chars.length() - 1;

            for (int i = 0; i < 32; i++) {
                int index = (int) (Math.random() * ccLength);
                buff.append(chars.charAt(index));
            }

            SharedPreferences.Editor editor = settings.edit();
            editor.putString("emulatorDeviceId", deviceId);
            editor.commit();

            deviceId = buff.toString();
        }

        deviceId = deviceId.toLowerCase();
    } catch (Exception e) {
        deviceId = null;
    }
}

From source file:com.master.metehan.filtereagle.Util.java

public static String getGeneralInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append(String.format("Interactive %B\r\n", isInteractive(context)));
    sb.append(String.format("Connected %B\r\n", isConnected(context)));
    sb.append(String.format("WiFi %B\r\n", isWifiActive(context)));
    sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context)));
    sb.append(String.format("Roaming %B\r\n", isRoaming(context)));

    sb.append(String.format("Type %s\r\n", getPhoneTypeName(tm.getPhoneType())));

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 || !hasPhoneStatePermission(context)) {
        if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
            sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(),
                    tm.getSimOperator()));
        if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN)
            sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(),
                    tm.getNetworkOperatorName(), tm.getNetworkOperator()));
    }/*w  w w. j a va  2s . co  m*/

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        sb.append(String.format("Battery optimizing %B\r\n",
                !pm.isIgnoringBatteryOptimizations(context.getPackageName())));

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}

From source file:org.restcomm.app.utillib.Reporters.WebReporter.WebReporter.java

public List<Carrier> getTopOperators(double latitude, double longitude, int radius, int mcc, int limit)
        throws LibException {
    List<Carrier> carriers = new ArrayList<Carrier>();
    try {//from  w w  w  .j  a  va  2 s .co  m
        String path = mHost + "/api/topop";

        TelephonyManager telephony = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        String ccode = telephony.getNetworkCountryIso();
        URL request = TopOperatorsRequest.getURL(path, mApiKey, latitude, longitude, radius, mcc, limit, ccode);
        HttpURLConnection connection = (HttpURLConnection) request.openConnection();
        connection.connect();
        verifyConnectionResponse(connection);
        String topResponseString = readString(connection);
        LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "getTopOperators", request.toString());

        //HttpClient mHttpClient = HttpUtils.createHttpClient();
        //HttpResponse topResponse = mHttpClient.execute(topRequest);
        //verifyResponse(topResponse);
        if (topResponseString.length() > 2) {
            SharedPreferences securePreferences = PreferenceKeys.getSecurePreferences(mContext);
            securePreferences.edit().putString(PreferenceKeys.Miscellaneous.TOPOP_RESPONSE, topResponseString)
                    .commit();
            securePreferences.edit()
                    .putString(PreferenceKeys.Miscellaneous.TOPOP_LAT, Double.toString(latitude)).commit();
            securePreferences.edit()
                    .putString(PreferenceKeys.Miscellaneous.TOPOP_LNG, Double.toString(longitude)).commit();
        }

        JSONArray operators = new JSONObject(topResponseString).getJSONArray("operators");
        for (int i = 0; i < operators.length(); i++) {
            Carrier carrier = new Carrier(operators.getJSONObject(i));
            carrier.loadLogo(mContext);
            if (carrier != null)
                carriers.add(carrier);
        }
    } catch (IOException e) {
        throw new LibException(e);
    } catch (Exception e) {
        throw new LibException(e);
    }
    return carriers;
}

From source file:com.andybotting.tubechaser.activity.Home.java

/**
 * Upload statistics to remote server//  w ww  .  j a v a  2 s  . co m
 */
private void uploadStats() {
    if (LOGV)
        Log.v(TAG, "Sending statistics");

    // gather all of the device info
    String app_version = "";
    try {
        try {
            PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
            app_version = pi.versionName;
        } catch (NameNotFoundException e) {
            app_version = "N/A";
        }

        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String device_uuid = tm.getDeviceId();
        String device_id = "00000000000000000000000000000000";
        if (device_uuid != null) {
            device_id = GenericUtil.MD5(device_uuid);
        }

        String mobile_country_code = tm.getNetworkCountryIso();
        String mobile_network_number = tm.getNetworkOperator();
        int network_type = tm.getNetworkType();

        // get the network type string
        String mobile_network_type = "N/A";
        switch (network_type) {
        case 0:
            mobile_network_type = "TYPE_UNKNOWN";
            break;
        case 1:
            mobile_network_type = "GPRS";
            break;
        case 2:
            mobile_network_type = "EDGE";
            break;
        case 3:
            mobile_network_type = "UMTS";
            break;
        case 4:
            mobile_network_type = "CDMA";
            break;
        case 5:
            mobile_network_type = "EVDO_0";
            break;
        case 6:
            mobile_network_type = "EVDO_A";
            break;
        case 7:
            mobile_network_type = "1xRTT";
            break;
        case 8:
            mobile_network_type = "HSDPA";
            break;
        case 9:
            mobile_network_type = "HSUPA";
            break;
        case 10:
            mobile_network_type = "HSPA";
            break;
        }

        String device_version = android.os.Build.VERSION.RELEASE;

        if (device_version == null) {
            device_version = "N/A";
        }

        String device_model = android.os.Build.MODEL;

        if (device_model == null) {
            device_model = "N/A";
        }

        String device_language = getResources().getConfiguration().locale.getLanguage();
        String home_function = mPreferenceHelper.defaultLaunchActivity();

        // post the data
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://tubechaser.andybotting.com/stats/app/send");
        post.setHeader("Content-Type", "application/x-www-form-urlencoded");

        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        pairs.add(new BasicNameValuePair("device_id", device_id));
        pairs.add(new BasicNameValuePair("app_version", app_version));
        pairs.add(new BasicNameValuePair("home_function", home_function));
        pairs.add(new BasicNameValuePair("device_model", device_model));
        pairs.add(new BasicNameValuePair("device_version", device_version));
        pairs.add(new BasicNameValuePair("device_language", device_language));
        pairs.add(new BasicNameValuePair("mobile_country_code", mobile_country_code));
        pairs.add(new BasicNameValuePair("mobile_network_number", mobile_network_number));
        pairs.add(new BasicNameValuePair("mobile_network_type", mobile_network_type));

        try {
            post.setEntity(new UrlEncodedFormEntity(pairs));
        } catch (UnsupportedEncodingException e) {
            // Do nothing
        }

        try {
            HttpResponse response = client.execute(post);
            response.getStatusLine().getStatusCode();
        } catch (Exception e) {
            if (LOGV)
                Log.v(TAG, "Error uploading stats: " + e.getMessage());
        }

    } catch (Exception e) {
        // Do nothing
    }

}

From source file:fr.inria.ucn.collectors.NetworkStateCollector.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private JSONObject getMobile(TelephonyManager tm) throws JSONException {
    JSONObject mob = new JSONObject();

    mob.put("call_state", tm.getCallState());
    mob.put("data_activity", tm.getDataActivity());
    mob.put("network_type", tm.getNetworkType());
    mob.put("network_type_str", Helpers.getTelephonyNetworkType(tm.getNetworkType()));
    mob.put("phone_type", tm.getPhoneType());
    mob.put("phone_type_str", Helpers.getTelephonyPhoneType(tm.getPhoneType()));
    mob.put("sim_state", tm.getSimState());
    mob.put("network_country", tm.getNetworkCountryIso());
    mob.put("network_operator", tm.getNetworkOperator());
    mob.put("network_operator_name", tm.getNetworkOperatorName());

    // current cell location
    CellLocation cl = tm.getCellLocation();
    if (cl != null) {
        JSONObject loc = new JSONObject();
        if (cl instanceof GsmCellLocation) {
            JSONObject cell = new JSONObject();
            cell.put("cid", ((GsmCellLocation) cl).getCid());
            cell.put("lac", ((GsmCellLocation) cl).getLac());
            cell.put("psc", ((GsmCellLocation) cl).getPsc());
            loc.put("gsm", cell);
        } else if (cl instanceof CdmaCellLocation) {
            JSONObject cell = new JSONObject();
            cell.put("bs_id", ((CdmaCellLocation) cl).getBaseStationId());
            cell.put("bs_lat", ((CdmaCellLocation) cl).getBaseStationLatitude());
            cell.put("bs_lon", ((CdmaCellLocation) cl).getBaseStationLongitude());
            cell.put("net_id", ((CdmaCellLocation) cl).getNetworkId());
            cell.put("sys_id", ((CdmaCellLocation) cl).getSystemId());
            loc.put("cdma", cell);
        }// ww  w  . j  a  v a 2s .c o  m
        mob.put("cell_location", loc);
    }

    // Cell neighbors
    List<NeighboringCellInfo> ncl = tm.getNeighboringCellInfo();
    if (ncl != null) {
        JSONArray cells = new JSONArray();
        for (NeighboringCellInfo nc : ncl) {
            JSONObject jnc = new JSONObject();
            jnc.put("cid", nc.getCid());
            jnc.put("lac", nc.getLac());
            jnc.put("network_type", nc.getNetworkType());
            jnc.put("network_type_str", Helpers.getTelephonyNetworkType(nc.getNetworkType()));
            jnc.put("psc", nc.getPsc());
            jnc.put("rssi", nc.getRssi());
            cells.put(jnc);
        }
        mob.put("neigh_cells", cells);
    }

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // only works for API level >=17
        List<CellInfo> aci = (List<CellInfo>) tm.getAllCellInfo();
        if (aci != null) {
            JSONArray cells = new JSONArray();
            for (CellInfo ci : aci) {
                JSONObject jci = new JSONObject();
                if (ci instanceof CellInfoGsm) {
                    CellInfoGsm cigsm = (CellInfoGsm) ci;
                    jci.put("is_registered", cigsm.isRegistered());
                    jci.put("type", "gsm");
                    jci.put("cid", cigsm.getCellIdentity().getCid());
                    jci.put("lac", cigsm.getCellIdentity().getLac());
                    jci.put("mcc", cigsm.getCellIdentity().getMcc());
                    jci.put("mnc", cigsm.getCellIdentity().getMnc());
                    jci.put("psc", cigsm.getCellIdentity().getPsc());

                    jci.put("asu_level", cigsm.getCellSignalStrength().getAsuLevel());
                    jci.put("level", cigsm.getCellSignalStrength().getLevel());
                    jci.put("dbm", cigsm.getCellSignalStrength().getDbm());

                } else if (ci instanceof CellInfoCdma) {
                    CellInfoCdma cicdma = (CellInfoCdma) ci;
                    jci.put("is_registered", cicdma.isRegistered());
                    jci.put("type", "cdma");
                    jci.put("bs_id", cicdma.getCellIdentity().getBasestationId());
                    jci.put("bs_lat", cicdma.getCellIdentity().getLatitude());
                    jci.put("bs_lon", cicdma.getCellIdentity().getLongitude());
                    jci.put("net_id", cicdma.getCellIdentity().getNetworkId());
                    jci.put("sys_id", cicdma.getCellIdentity().getSystemId());

                    jci.put("asu_level", cicdma.getCellSignalStrength().getAsuLevel());
                    jci.put("dbm", cicdma.getCellSignalStrength().getDbm());
                    jci.put("level", cicdma.getCellSignalStrength().getLevel());
                    jci.put("cdma_dbm", cicdma.getCellSignalStrength().getCdmaDbm());
                    jci.put("cdma_ecio", cicdma.getCellSignalStrength().getCdmaEcio());
                    jci.put("cdma_level", cicdma.getCellSignalStrength().getCdmaLevel());
                    jci.put("evdo_dbm", cicdma.getCellSignalStrength().getEvdoDbm());
                    jci.put("evdo_ecio", cicdma.getCellSignalStrength().getEvdoEcio());
                    jci.put("evdo_level", cicdma.getCellSignalStrength().getEvdoLevel());
                    jci.put("evdo_snr", cicdma.getCellSignalStrength().getEvdoSnr());

                } else if (ci instanceof CellInfoWcdma) {
                    CellInfoWcdma ciwcdma = (CellInfoWcdma) ci;
                    jci.put("is_registered", ciwcdma.isRegistered());
                    jci.put("type", "wcdma");
                    jci.put("cid", ciwcdma.getCellIdentity().getCid());
                    jci.put("lac", ciwcdma.getCellIdentity().getLac());
                    jci.put("mcc", ciwcdma.getCellIdentity().getMcc());
                    jci.put("mnc", ciwcdma.getCellIdentity().getMnc());
                    jci.put("psc", ciwcdma.getCellIdentity().getPsc());

                    jci.put("asu_level", ciwcdma.getCellSignalStrength().getAsuLevel());
                    jci.put("dbm", ciwcdma.getCellSignalStrength().getDbm());
                    jci.put("level", ciwcdma.getCellSignalStrength().getLevel());

                } else if (ci instanceof CellInfoLte) {
                    CellInfoLte cilte = (CellInfoLte) ci;
                    jci.put("is_registered", cilte.isRegistered());
                    jci.put("type", "lte");
                    jci.put("ci", cilte.getCellIdentity().getCi());
                    jci.put("mcc", cilte.getCellIdentity().getMcc());
                    jci.put("mnc", cilte.getCellIdentity().getMnc());
                    jci.put("pci", cilte.getCellIdentity().getPci());
                    jci.put("tac", cilte.getCellIdentity().getTac());

                    jci.put("asu_level", cilte.getCellSignalStrength().getAsuLevel());
                    jci.put("dbm", cilte.getCellSignalStrength().getDbm());
                    jci.put("level", cilte.getCellSignalStrength().getLevel());
                    jci.put("timing_adv", cilte.getCellSignalStrength().getTimingAdvance());

                }
                cells.put(jci);
            }
            mob.put("all_cells", cells);
        }
    }
    return mob;
}

From source file:com.master.metehan.filtereagle.Util.java

public static boolean isInternational(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && hasPhoneStatePermission(context)) {
        int dataSubId;
        try {/*from   ww  w. ja  v a  2 s. c o  m*/
            dataSubId = Settings.Global.getInt(context.getContentResolver(), "multi_sim_data_call", -1);
        } catch (Throwable ignored) {
            dataSubId = -1;
        }
        if (dataSubId >= 0) {
            SubscriptionManager sm = SubscriptionManager.from(context);
            SubscriptionInfo si = sm.getActiveSubscriptionInfo(dataSubId);
            if (si != null && si.getCountryIso() != null)
                try {
                    Method getNetworkCountryIso = tm.getClass().getMethod("getNetworkCountryIsoForSubscription",
                            int.class);
                    getNetworkCountryIso.setAccessible(true);
                    String networkCountryIso = (String) getNetworkCountryIso.invoke(tm, dataSubId);
                    Log.d(TAG, "SIM=" + si.getCountryIso() + " network=" + networkCountryIso);
                    return !si.getCountryIso().equals(networkCountryIso);
                } catch (Throwable ex) {
                    Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    sendCrashReport(ex, context);
                }
        }
    }

    return (tm == null || tm.getSimCountryIso() == null
            || !tm.getSimCountryIso().equals(tm.getNetworkCountryIso()));
}

From source file:com.tapjoy.TapjoyConnectCore.java

/**
 * Initialize data from the device information and application info.
 * This data is used in our URL connection to the Tapjoy server. 
 *///from w ww .ja  v  a 2s. co m
private void init() {
    PackageManager manager = context.getPackageManager();

    try {
        // ANDROID_ID
        androidID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

        // Get app version.
        PackageInfo packageInfo = manager.getPackageInfo(context.getPackageName(), 0);
        appVersion = packageInfo.versionName;

        // Device platform.  Same as device type.
        deviceType = TapjoyConstants.TJC_DEVICE_PLATFORM_TYPE;
        platformName = TapjoyConstants.TJC_DEVICE_PLATFORM_TYPE;

        // Get the device model.
        deviceModel = android.os.Build.MODEL;
        deviceManufacturer = android.os.Build.MANUFACTURER;

        // Get the Android OS Version.
        deviceOSVersion = android.os.Build.VERSION.RELEASE;

        // Get the device country and language code.
        deviceCountryCode = Locale.getDefault().getCountry();
        deviceLanguage = Locale.getDefault().getLanguage();

        // Tapjoy SDK Library version.
        libraryVersion = TapjoyConstants.TJC_LIBRARY_VERSION_NUMBER;

        SharedPreferences settings = context.getSharedPreferences(TapjoyConstants.TJC_PREFERENCE, 0);

        try {
            TelephonyManager telephonyManager = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);

            if (telephonyManager != null) {
                deviceID = telephonyManager.getDeviceId();

                carrierName = telephonyManager.getNetworkOperatorName();
                carrierCountryCode = telephonyManager.getNetworkCountryIso();

                // getNetworkOperator() returns MCC + MNC, so make sure it's 5 or 6 digits total.
                // MCC is 3 digits
                // MNC is 2 or 3 digits
                if (telephonyManager.getNetworkOperator() != null
                        && (telephonyManager.getNetworkOperator().length() == 5
                                || telephonyManager.getNetworkOperator().length() == 6)) {
                    mobileCountryCode = telephonyManager.getNetworkOperator().substring(0, 3);
                    mobileNetworkCode = telephonyManager.getNetworkOperator().substring(3);
                }
            }

            TapjoyLog.i(TAPJOY_CONNECT, "deviceID: " + deviceID);

            boolean invalidDeviceID = false;

            //----------------------------------------
            // Is the device ID null or empty?
            //----------------------------------------
            if (deviceID == null) {
                TapjoyLog.e(TAPJOY_CONNECT, "Device id is null.");
                invalidDeviceID = true;
            } else
            //----------------------------------------
            // Is this an emulator device ID?
            //----------------------------------------
            if (deviceID.length() == 0 || deviceID.equals("000000000000000") || deviceID.equals("0")) {
                TapjoyLog.e(TAPJOY_CONNECT, "Device id is empty or an emulator.");
                invalidDeviceID = true;
            }
            //----------------------------------------
            // Valid device ID.
            //----------------------------------------
            else {
                // Lower case the device ID.
                deviceID = deviceID.toLowerCase();
            }

            TapjoyLog.i(TAPJOY_CONNECT, "ANDROID SDK VERSION: " + android.os.Build.VERSION.SDK);

            // Is this at least Android 2.3+?
            // Then let's get the serial.
            if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 9) {
                TapjoyLog.i(TAPJOY_CONNECT, "TRYING TO GET SERIAL OF 2.3+ DEVICE...");

                // THIS CLASS IS ONLY LOADED FOR ANDROID 2.3+
                TapjoyHardwareUtil hardware = new TapjoyHardwareUtil();

                serialID = hardware.getSerial();

                // Is there no IMEI or MEID?
                if (invalidDeviceID) {
                    deviceID = serialID;
                }

                TapjoyLog.i(TAPJOY_CONNECT, "====================");
                TapjoyLog.i(TAPJOY_CONNECT, "SERIAL: deviceID: [" + deviceID + "]");
                TapjoyLog.i(TAPJOY_CONNECT, "====================");

                //----------------------------------------
                // Is the device ID null or empty?
                //----------------------------------------
                if (deviceID == null) {
                    TapjoyLog.e(TAPJOY_CONNECT, "SERIAL: Device id is null.");
                    invalidDeviceID = true;
                } else
                //----------------------------------------
                // Is this an emulator device ID?
                //----------------------------------------
                if (deviceID.length() == 0 || deviceID.equals("000000000000000") || deviceID.equals("0")
                        || deviceID.equals("unknown")) {
                    TapjoyLog.e(TAPJOY_CONNECT, "SERIAL: Device id is empty or an emulator.");
                    invalidDeviceID = true;
                }
                //----------------------------------------
                // Valid device ID.
                //----------------------------------------
                else {
                    // Lower case the device ID.
                    deviceID = deviceID.toLowerCase();
                    invalidDeviceID = false;
                }
            }

            // Is the device ID invalid?  This is probably an emulator or pre-production device.
            if (invalidDeviceID) {
                StringBuffer buff = new StringBuffer();
                buff.append("EMULATOR");
                String deviceId = settings.getString(TapjoyConstants.PREF_EMULATOR_DEVICE_ID, null);

                // Do we already have an emulator device id stored for this device?
                if (deviceId != null && !deviceId.equals("")) {
                    deviceID = deviceId;
                }
                // Otherwise generate a deviceID for emulator testing.
                else {
                    String constantChars = "1234567890abcdefghijklmnopqrstuvw";

                    for (int i = 0; i < 32; i++) {
                        int randomChar = (int) (Math.random() * 100);
                        int ch = randomChar % 30;
                        buff.append(constantChars.charAt(ch));
                    }

                    deviceID = buff.toString().toLowerCase();

                    // Save the emulator device ID in the prefs so we can reuse it.
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString(TapjoyConstants.PREF_EMULATOR_DEVICE_ID, deviceID);
                    editor.commit();
                }
            }
        } catch (Exception e) {
            TapjoyLog.e(TAPJOY_CONNECT, "Error getting deviceID. e: " + e.toString());
            deviceID = null;
        }

        // Set the userID to the deviceID as the initial value.
        if (userID.length() == 0)
            userID = deviceID;

        // Save the SHA-2 hash of the device id.
        sha2DeviceID = TapjoyUtil.SHA256(deviceID);

        // Get screen density, dimensions and layout.
        try {
            // This is a backwards compatibility fix for Android 1.5 which has no display metric API.
            // If this is 1.6 or higher, then load the class, otherwise the class never loads and
            // no crash occurs.
            if (Integer.parseInt(android.os.Build.VERSION.SDK) > 3) {
                TapjoyDisplayMetricsUtil displayMetricsUtil = new TapjoyDisplayMetricsUtil(context);

                deviceScreenDensity = "" + displayMetricsUtil.getScreenDensity();
                deviceScreenLayoutSize = "" + displayMetricsUtil.getScreenLayoutSize();
            }
        } catch (Exception e) {
            TapjoyLog.e(TAPJOY_CONNECT, "Error getting screen density/dimensions/layout: " + e.toString());
        }

        // Get mac address.
        try {
            WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

            if (wifiManager != null) {
                WifiInfo wifiInfo = wifiManager.getConnectionInfo();

                if (wifiInfo != null) {
                    macAddress = wifiInfo.getMacAddress();

                    if (macAddress != null && macAddress.length() > 0) {
                        macAddress = macAddress.toUpperCase();
                        sha1MacAddress = TapjoyUtil.SHA1(macAddress);
                    }
                }
            }
        } catch (Exception e) {
            TapjoyLog.e(TAPJOY_CONNECT, "Error getting device mac address: " + e.toString());
        }

        // Alternate market.
        if (getFlagValue(TapjoyConnectFlag.ALTERNATE_MARKET) != null) {
            marketName = getFlagValue(TapjoyConnectFlag.ALTERNATE_MARKET);

            // Check for existing/supported market names.
            ArrayList<String> supportedMarketNames = new ArrayList<String>();
            supportedMarketNames.add(TapjoyConnectFlag.MARKET_GFAN);

            // Warning for undefined market names.
            if (!supportedMarketNames.contains(marketName)) {
                Log.w(TAPJOY_CONNECT, "Warning -- undefined ALTERNATE_MARKET: " + marketName);
            }
        }

        // Get the referral URL
        String tempReferralURL = settings.getString(TapjoyConstants.PREF_REFERRAL_URL, null);
        if (tempReferralURL != null && !tempReferralURL.equals(""))
            referralURL = tempReferralURL;

        // Get the client package name.
        clientPackage = context.getPackageName();

        TapjoyLog.i(TAPJOY_CONNECT, "Metadata successfully loaded");

        TapjoyLog.i(TAPJOY_CONNECT, "APP_ID = [" + appID + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "ANDROID_ID: [" + androidID + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "CLIENT_PACKAGE = [" + clientPackage + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "deviceID: [" + deviceID + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "sha2DeviceID: [" + sha2DeviceID + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "" + TapjoyConstants.TJC_DEVICE_SERIAL_ID + ": [" + serialID + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "" + TapjoyConstants.TJC_DEVICE_MAC_ADDRESS + ": [" + macAddress + "]");
        TapjoyLog.i(TAPJOY_CONNECT,
                "" + TapjoyConstants.TJC_DEVICE_SHA1_MAC_ADDRESS + ": [" + sha1MacAddress + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "deviceName: [" + deviceModel + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "deviceManufacturer: [" + deviceManufacturer + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "deviceType: [" + deviceType + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "libraryVersion: [" + libraryVersion + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "deviceOSVersion: [" + deviceOSVersion + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "COUNTRY_CODE: [" + deviceCountryCode + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "LANGUAGE_CODE: [" + deviceLanguage + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "density: [" + deviceScreenDensity + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "screen_layout: [" + deviceScreenLayoutSize + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "carrier_name: [" + carrierName + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "carrier_country_code: [" + carrierCountryCode + "]");
        TapjoyLog.i(TAPJOY_CONNECT,
                "" + TapjoyConstants.TJC_MOBILE_COUNTRY_CODE + ": [" + mobileCountryCode + "]");
        TapjoyLog.i(TAPJOY_CONNECT,
                "" + TapjoyConstants.TJC_MOBILE_NETWORK_CODE + ": [" + mobileNetworkCode + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "" + TapjoyConstants.TJC_MARKET_NAME + ": [" + marketName + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "referralURL: [" + referralURL + "]");

        if (connectFlags != null) {
            TapjoyLog.i(TAPJOY_CONNECT, "Connect Flags:");
            TapjoyLog.i(TAPJOY_CONNECT, "--------------------");

            Set<Entry<String, String>> entries = connectFlags.entrySet();
            Iterator<Entry<String, String>> iterator = entries.iterator();

            while (iterator.hasNext()) {
                Entry<String, String> item = iterator.next();
                TapjoyLog.i(TAPJOY_CONNECT,
                        "key: " + item.getKey() + ", value: " + Uri.encode(item.getValue()));
            }
        }
    } catch (Exception e) {
        TapjoyLog.e(TAPJOY_CONNECT, "Error initializing Tapjoy parameters.  e=" + e.toString());
    }
}

From source file:com.sonetel.ui.dialpad.DialerFragment.java

protected boolean isLocationChanged(Context context) {
    String CurrentLocation = null;
    String StoredLocation = null;
    PreferencesWrapper prefWrapper = new PreferencesWrapper(context);
    StoredLocation = prefWrapper.getCurrentLocation();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    CurrentLocation = tm.getNetworkCountryIso();

    if (StoredLocation != null && CurrentLocation != null) {
        if (StoredLocation.equalsIgnoreCase(CurrentLocation))
            return false;
    }//w ww  . j av  a  2  s .  co  m
    return true;
}