Example usage for android.telephony TelephonyManager getCellLocation

List of usage examples for android.telephony TelephonyManager getCellLocation

Introduction

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

Prototype

@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
public CellLocation getCellLocation() 

Source Link

Document

Returns the current location of the device.

Usage

From source file:Main.java

public static int getLat(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();

    return cellLocation == null ? -1 : cellLocation.getLac();
}

From source file:com.wbtech.common.CommonUtil.java

/**
 * ??//  w w  w .j a v a2  s .  c o m
 * @throws Exception
 */
public static SCell getCellInfo(Context context) throws Exception {
    SCell cell = new SCell();
    /** API?? */
    TelephonyManager mTelNet = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation location = (GsmCellLocation) mTelNet.getCellLocation();
    if (location == null) {
        if (UmsConstants.DebugMode) {
            Log.e("GsmCellLocation Error", "GsmCellLocation is null");
        }
        return null;
    }

    String operator = mTelNet.getNetworkOperator();
    //        System.out.println("operator------>"+operator.toString());
    int mcc = Integer.parseInt(operator.substring(0, 3));
    int mnc = Integer.parseInt(operator.substring(3));
    int cid = location.getCid();
    int lac = location.getLac();

    /** ? */
    cell.MCC = mcc;
    cell.MCCMNC = Integer.parseInt(operator);
    cell.MNC = mnc;
    cell.LAC = lac;
    cell.CID = cid;

    return cell;
}

From source file:com.github.nutomic.pegasus.LocationService.java

/**
 * Register CellListener and show Notification.
 *///from w  w w.ja  va  2 s  .  c  o m
@Override
public void onCreate() {
    super.onCreate();
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mCellListener = new CellListener(tm.getPhoneType());
    tm.listen(mCellListener, PhoneStateListener.LISTEN_CELL_LOCATION);
    // Force update.
    mCellListener.onCellLocationChanged(tm.getCellLocation());
}

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);
        }/*from ww  w  . j  a v  a  2s .  com*/
        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.lewa.crazychapter11.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    //set to full screen
    // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN);

    ///set to no title
    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    // acionBar = getSupportActionBar();
    // acionBar = getActionBar();
    // acionBar.hide();

    // Window win = getWindow();
    //          win.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    //          win.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS  | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);  
    //          win.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);  
    // win.setStatusBarColor(Color.TRANSPARENT);  
    // win.setNavigationBarColor(Color.TRANSPARENT);

    /*/// ww  w  .  j ava 2  s.c o  m
       win.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
       win.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS  | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);  
       win.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);  
       win.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);  
       win.setStatusBarColor(Color.TRANSPARENT);  
       win.setNavigationBarColor(Color.TRANSPARENT);
    //*/

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    /* setTheme(R.style.CrazyTheme); */
    AddGameBtn();
    AddNoification();
    LookupContact();
    AddServiceBtn();
    broadcastMain();
    mediaPlayerMain();
    mediaRecordSoundMain();
    cameraMain();
    recordvideoMain();
    queMySql();
    TestFragment();
    justForTest();
    LoadJson();
    AddTestBtn();
    AddUsageStatsBtn();
    AddPeopleProvideBtn();
    getInput();

    ////just for test shutdown broadcast receiver
    IntentFilter mIntentFilter = new IntentFilter("android.intent.action.ACTION_SHUTDOWN");
    mIntentFilter.addAction("com.lewa.alarm.test");
    mIntentFilter.addAction("android.provider.Telephony.SECRET_CODE");
    mIntentFilter.addAction("android.intent.action.SCREEN_ON");
    mIntentFilter.addAction("android.intent.action.SCREEN_OFF");
    mShoutdown = new shutdownReceiver();
    registerReceiver(mShoutdown, mIntentFilter);
    ////test      

    preferences = getSharedPreferences("crazyit", MODE_WORLD_WRITEABLE | MODE_WORLD_READABLE);
    editor = preferences.edit();

    preferencestime = getSharedPreferences("RMS_Shutdown_time", MODE_WORLD_WRITEABLE | MODE_WORLD_READABLE);
    editortime = preferencestime.edit();

    SharedShutdownTimeRead();

    AddSharedPreBtn();

    etNum = (EditText) findViewById(R.id.etNum);

    // //
    int maxLength = 4;

    InputFilter[] fArray = new InputFilter[1];

    fArray[0] = new InputFilter.LengthFilter(maxLength);

    etNum.setFilters(fArray);
    // //

    calThread = new CalThread();
    calThread.start();

    Log.i("algerheMain", "MainActivity onCreate in!!");
    String page = getString(R.string.str_page, "345", "24");
    Log.i("algerheMain", "page=" + page);

    // /just for test here
    ComponentName comp = getIntent().getComponent();
    show_txt = (EditText) findViewById(R.id.show_txt);
    show_txt.setText(
            "??" + comp.getPackageName() + " \n ??" + comp.getClassName());

    ////MD5 check item
    ///1.IMEI
    TelephonyManager TelephonyMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    String szImei = TelephonyMgr.getDeviceId();
    String m_szSIMSerialNm = TelephonyMgr.getSimSerialNumber();
    CellLocation m_location = TelephonyMgr.getCellLocation();
    String m_Line1Number = TelephonyMgr.getLine1Number();
    String m_OperatorName = TelephonyMgr.getSimOperatorName();
    Log.i("algerheTelephonyMgr", "szImei=" + szImei);
    Log.i("algerheTelephonyMgr", "m_szSIMSerialNm=" + m_szSIMSerialNm);
    Log.i("algerheTelephonyMgr", "m_location=" + m_location);
    Log.i("algerheTelephonyMgr", "m_Line1Number=" + m_Line1Number);
    Log.i("algerheTelephonyMgr", "m_OperatorName=" + m_OperatorName);

    Log.i("algerheMain01", "szImei=" + szImei);
    Log.i("algerheMain01", "m_szSIMSerialNm=" + m_szSIMSerialNm);

    ///2.Pseudo-Unique ID
    String m_szDevIDShort = "35" + //we make this look like a valid IMEI 
            Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10
            + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10
            + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10
            + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10
            + Build.USER.length() % 10; //13 digits

    Log.i("algerheMain01", "m_szDevIDShort=" + m_szDevIDShort);

    ///3. Android ID
    String m_szAndroidID = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    Log.i("algerheMain01", "m_szAndroidID=" + m_szAndroidID);

    ///4.WLAN MAC Address string
    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    String m_szWLANMAC = "unknow_wifi_mac";
    if (wm != null && wm.getConnectionInfo() != null) {
        m_szWLANMAC = wm.getConnectionInfo().getMacAddress();
    }

    Log.i("algerheMain01", "m_szWLANMAC=" + m_szWLANMAC);

    ///5.BT MAC Address string
    BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth adapter      
    m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    String m_szBTMAC = m_BluetoothAdapter.getAddress();

    Log.i("algerheMain01", "m_szBTMAC=" + m_szBTMAC);

    ///6.sim serial number .getSimSerialNumber()

    // /

    ///reflect test   
    checkMethod();

    // */
    final Intent alarmIntent = new Intent();
    Log.i("algerheMain00", "isLewaRom=" + isLewaRom(this, alarmIntent));

    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0x4567) {
                String languageStr = null;
                String countryStr = null;

                Locale[] locList = Locale.getAvailableLocales();

                for (int i = 0; i < locList.length; i++) {
                    languageStr += locList[i].getLanguage();
                    countryStr += locList[i].getCountry();
                }
                // show_txt = (EditText) findViewById(R.id.show_txt);
                show_txt.setText("" + languageStr + " \n " + countryStr);
            } else if (msg.what == 0x2789) {
                Log.i("algerheAlarm", "send alarm message in time=" + System.currentTimeMillis() + "\n action="
                        + alarmIntent.getAction());

                // sendBroadcast(alarmIntent);
            }
        }
    };

    // String strApkPath = intent.getStringExtra("apkPath");
    //         String strCmd = "pm install -r " + strApkPath;
    //         try {
    //             Process install = Runtime.getRuntime().exec(strCmd);
    //             Log.d(TAG, "install = " + install + ", strCmd =" + strCmd);
    //         }catch (Exception ex){
    //             Log.d(TAG, ex.getMessage());
    //         }   
    // */
}

From source file:ch.ethz.coss.nervousnet.vm.sensors.ConnectivitySensor.java

public void runConnectivitySensor() {
    Log.d(LOG_TAG, "Inside runConnectivitySensor");
    if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(context,
            android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;/*from   w ww . j  av a2 s  .  c  o  m*/
    }
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    int networkType = -1;
    boolean isRoaming = false;
    if (isConnected) {
        networkType = activeNetwork.getType();
        isRoaming = activeNetwork.isRoaming();
    }

    String wifiHashId = "";
    int wifiStrength = Integer.MIN_VALUE;

    if (networkType == ConnectivityManager.TYPE_WIFI) {
        WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wi = wm.getConnectionInfo();
        StringBuilder wifiInfoBuilder = new StringBuilder();
        wifiInfoBuilder.append(wi.getBSSID());
        wifiInfoBuilder.append(wi.getSSID());
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
            messageDigest.update(wifiInfoBuilder.toString().getBytes());
            wifiHashId = new String(messageDigest.digest());
        } catch (NoSuchAlgorithmException e) {
        }
        wifiStrength = wi.getRssi();
    }

    byte[] cdmaHashId = new byte[32];
    byte[] lteHashId = new byte[32];
    byte[] gsmHashId = new byte[32];
    byte[] wcdmaHashId = new byte[32];

    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    List<CellInfo> cis = tm.getAllCellInfo();
    if (cis != null) {
        // New method
        for (CellInfo ci : cis) {
            if (ci.isRegistered()) {
                if (ci instanceof CellInfoCdma) {
                    CellInfoCdma cic = (CellInfoCdma) ci;
                    cdmaHashId = generateMobileDigestId(cic.getCellIdentity().getSystemId(),
                            cic.getCellIdentity().getNetworkId(), cic.getCellIdentity().getBasestationId());
                }
                if (ci instanceof CellInfoGsm) {
                    CellInfoGsm cic = (CellInfoGsm) ci;
                    gsmHashId = generateMobileDigestId(cic.getCellIdentity().getMcc(),
                            cic.getCellIdentity().getMnc(), cic.getCellIdentity().getCid());
                }
                if (ci instanceof CellInfoLte) {
                    CellInfoLte cic = (CellInfoLte) ci;
                    lteHashId = generateMobileDigestId(cic.getCellIdentity().getMcc(),
                            cic.getCellIdentity().getMnc(), cic.getCellIdentity().getCi());
                }
                if (ci instanceof CellInfoWcdma) {
                    CellInfoWcdma cic = (CellInfoWcdma) ci;
                    wcdmaHashId = generateMobileDigestId(cic.getCellIdentity().getMcc(),
                            cic.getCellIdentity().getMnc(), cic.getCellIdentity().getCid());
                }
            }
        }
    } else {
        // Legacy method
        CellLocation cl = tm.getCellLocation();
        if (cl instanceof CdmaCellLocation) {
            CdmaCellLocation cic = (CdmaCellLocation) cl;
            cdmaHashId = generateMobileDigestId(cic.getSystemId(), cic.getNetworkId(), cic.getBaseStationId());
        }
        if (cl instanceof GsmCellLocation) {
            GsmCellLocation cic = (GsmCellLocation) cl;
            gsmHashId = generateMobileDigestId(cic.getLac(), 0, cic.getCid());
        }
    }

    StringBuilder mobileHashBuilder = new StringBuilder();
    mobileHashBuilder.append(new String(cdmaHashId));
    mobileHashBuilder.append(new String(lteHashId));
    mobileHashBuilder.append(new String(gsmHashId));
    mobileHashBuilder.append(new String(wcdmaHashId));

    dataReady(new ConnectivityReading(System.currentTimeMillis(), isConnected, networkType, isRoaming,
            wifiHashId, wifiStrength, mobileHashBuilder.toString()));

}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * @inheritDoc/*from   w  w w.jav a2  s  .  c  om*/
 */
public String getProperty(String key, String defaultValue) {
    if (key.equalsIgnoreCase("cn1_push_prefix")) {
        /*if(!checkForPermission(Manifest.permission.READ_PHONE_STATE, "This is required to get notifications")){
        return "";
        }*/
        boolean has = hasAndroidMarket();
        if (has) {
            return "gcm";
        }
        return defaultValue;
    }
    if ("OS".equals(key)) {
        return "Android";
    }
    if ("androidId".equals(key)) {
        return Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
    }

    if ("cellId".equals(key)) {
        try {
            if (!checkForPermission(Manifest.permission.READ_PHONE_STATE,
                    "This is required to get the cellId")) {
                return defaultValue;
            }
            String serviceName = Context.TELEPHONY_SERVICE;
            TelephonyManager telephonyManager = (TelephonyManager) getContext().getSystemService(serviceName);
            int cellId = ((GsmCellLocation) telephonyManager.getCellLocation()).getCid();
            return "" + cellId;
        } catch (Throwable t) {
            return defaultValue;
        }
    }
    if ("AppName".equals(key)) {

        final PackageManager pm = getContext().getPackageManager();
        ApplicationInfo ai;
        try {
            ai = pm.getApplicationInfo(getContext().getPackageName(), 0);
        } catch (NameNotFoundException e) {
            ai = null;
        }
        String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : null);
        if (applicationName == null) {
            return defaultValue;
        }
        return applicationName;
    }
    if ("AppVersion".equals(key)) {
        try {
            PackageInfo i = getContext().getPackageManager()
                    .getPackageInfo(getContext().getApplicationInfo().packageName, 0);
            return i.versionName;
        } catch (NameNotFoundException ex) {
            ex.printStackTrace();
        }
        return defaultValue;
    }
    if ("Platform".equals(key)) {
        String p = System.getProperty("platform");
        if (p == null) {
            return defaultValue;
        }
        return p;
    }
    if ("User-Agent".equals(key)) {
        String ua = getUserAgent();
        if (ua == null) {
            return defaultValue;
        }
        return ua;
    }
    if ("OSVer".equals(key)) {
        return "" + android.os.Build.VERSION.RELEASE;
    }
    if ("DeviceName".equals(key)) {
        return "" + android.os.Build.MODEL;
    }
    try {
        if ("IMEI".equals(key) || "UDID".equals(key)) {
            if (!checkForPermission(Manifest.permission.READ_PHONE_STATE,
                    "This is required to get the device ID")) {
                return "";
            }
            TelephonyManager tm = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
            String imei = null;
            if (tm != null && tm.getDeviceId() != null) {
                // for phones or 3g tablets
                imei = tm.getDeviceId();
            } else {
                try {
                    imei = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
                } catch (Throwable t) {
                    com.codename1.io.Log.e(t);
                }
            }
            return imei;
        }
        if ("MSISDN".equals(key)) {
            if (!checkForPermission(Manifest.permission.READ_PHONE_STATE,
                    "This is required to get the device ID")) {
                return "";
            }
            TelephonyManager tm = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
            return tm.getLine1Number();
        }
    } catch (Throwable t) {
        // will be caused by no permissions.
        return defaultValue;
    }

    if (getActivity() != null) {
        android.content.Intent intent = getActivity().getIntent();
        if (intent != null) {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                String value = extras.getString(key);
                if (value != null) {
                    return value;
                }
            }
        }
    }

    //these keys/values are from the Application Resources (strings values)
    try {
        int id = getContext().getResources().getIdentifier(key, "string",
                getContext().getApplicationInfo().packageName);
        if (id != 0) {
            String val = getContext().getResources().getString(id);
            return val;
        }
    } catch (Exception e) {
    }
    return System.getProperty(key, super.getProperty(key, defaultValue));
}