问题
I'm successfully getting GsmCellLocation
and related cid and lac information but the PSC (primary scrambling code) of the serving cell is always coming back with the initialized value -1.
Anyone able to 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 permissions necessary. My neighbor list returns empty as well but that's not a concern at the moment.
回答1:
PSC is available only on UMTS network.
Check network type getNetworkType if it's NETWORK_TYPE_UMTS
and not NETWORK_TYPE_EDGE
回答2:
I have read that the this works on some phones - the Google nexus phone being one of them.
I tried to run your test code on my Motorolla Razr - it returns -1.
By looking at the android source code (GsmServiceStateTracker.java) it looks like this feature is optional and most likely not implemented on many phones. The information you are looking for is sent as unsolicited message from the GSM modem and its not used for anything else (As far as I can see from the android sources) than the value returned from getPsc()
.
I mean why implement it if you don't have to.
I also tried to extend your test code to obtain info about neighbouring cells which can also be used to get their PSC values. It does not work, as the at command used for getting neighbouring cell info is not implemented in my phone's 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 find out what phones implement this, you should add a test to some benchmark app and hopefully get some results in time.
来源:https://stackoverflow.com/questions/10613736/getpsc-using-gsmcelllocation-always-returns-1