这可能已经过时了,但是您知道错误是什么吗?
我收到错误消息,“获取单元位置信息时出错”。
我找到了导致此错误的源代码。
private void requestRefLocation(int flags)
{
TelephonyManager phone = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
if (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
{
GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation();
if ((gsm_cell != null)
&& (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
&& (phone.getNetworkOperator() != null)
&& (phone.getNetworkOperator().length() > 3))
{
int type;
int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3));
int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3));
int networkType = phone.getNetworkType();
if (networkType == TelephonyManager.NETWORK_TYPE_UMTS
|| networkType == TelephonyManager.NETWORK_TYPE_HSDPA
|| networkType == TelephonyManager.NETWORK_TYPE_HSUPA
|| networkType == TelephonyManager.NETWORK_TYPE_HSPA)
{
type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
}
else
{
type = AGPS_REF_LOCATION_TYPE_GSM_CELLID;
}
native_agps_set_ref_location_cellid(type, mcc, mnc, gsm_cell.getLac(), gsm_cell.getCid());
}
else
{
Log.e(TAG, "Error getting cell location info.");
}
} else {
Log.e(TAG, "CDMA not supported.");
}
}
注意检查语句
if ((gsm_cell != null)
&& (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
&& (phone.getNetworkOperator() != null)
&& (phone.getNetworkOperator().length() > 3))
{
它以某种方式导致您面临的问题。当然,通过连接到 WIFI 网络,您仍然可以获得您的位置,因为它使用不同的方式来获取它。我希望这能回答你的问题。