GetPsc () using GsmCellLocation always returns -1

I successfully get GsmCellLocation and the associated cid and lac information, but the serving cell PSC (primary scrambling code) always returns with an initialized value of -1. Anyone who can get the real PSC value of the serving cell?

 telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation(); psc = cellLocation.getPsc(); Log.d(TAG, "PSC = " + psc); 

I have all the necessary permissions. The list of my neighbors is also empty, but at the moment this is not a problem.

+4
source share
2 answers

PSC is only available on the UMTS network.
Check the network type getNetworkType if it is NETWORK_TYPE_UMTS and not NETWORK_TYPE_EDGE

+1
source

I read that this works on some phones - one of them is the Google Nexus phone.

I tried running your test code on my Motorolla Razr - it returns -1.

Having studied the Android source code (GsmServiceStateTracker.java), it seems that this feature is optional and most likely not implemented on many phones. The information you are looking for is sent as an unsolicited message from a GSM modem and is not used for anything else (as far as I can see from android sources) than the value returned from getPsc() .

I mean, why implement this if you don't need to.

I also tried expanding your test code to get information about neighboring cells, which can also be used to get their PSC values. It does not work, because the at command, used to obtain information about neighboring cells, is not implemented in the modem of the GSM modem.

 TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation(); Log.d(TAG, "cid = " + cellLocation.getCid()); Log.d(TAG, "lac = " + cellLocation.getLac()); int psc = cellLocation.getPsc(); Log.d(TAG, "PSC = " + psc); List<NeighboringCellInfo> neighCell = null; neighCell = telephonyManager.getNeighboringCellInfo(); for (int i = 0; i < neighCell.size(); i++) { NeighboringCellInfo thisCell = neighCell.get(i); int CID = thisCell.getCid(); int RSSI = thisCell.getRssi(); int PSC = thisCell.getPsc(); Log.d(TAG, " "+CID+" - "+RSSI + " - " + PSC); } 

If you really want to know which phones implement this, you should add a test to some testing application and hopefully get some results on time.

0
source

Source: https://habr.com/ru/post/1412722/


All Articles