问题描述
我正在尝试将此函数转换为使用 CellIdentityGsm 类型,以便我可以访问 BSIC。 onCellLocationChanged 仅与 CellLocation 类型兼容。我如何打字才能使这项工作?下面的代码不起作用,是我对类型转换的解释,感谢您的帮助,如果有任何问题,请告诉我。
顶部函数是使用 CellLocation 的原始函数并且可以工作,底部函数是我尝试转换为 CellIdentityGsm 但失败的函数。
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onCellLocationChanged(CellLocation cellLocation) {
super.onCellLocationChanged(cellLocation);
if(cellLocation == null) return;
Log.i(LOG_TAG,"onCellLocationChanged");
String desc = "\"" + cellLocation.getClass().getSimpleName() + "\" : " + cellLocation.toString();
textView.setText("Cell Info Logger\nCell Location\n"+desc);
logger.write(desc);
} // END onCellLocationChanged
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onCellLocationChanged(CellIdentityGsm cellLocation) {
super.onCellLocationChanged((CellLocation) cellLocation);
if(cellLocation == null) return;
Log.i(LOG_TAG,"onCellLocationChanged");
String desc = "\"" + cellLocation.getClass().getSimpleName() + "\" : " + cellLocation.getBsic() + " : " + cellLocation.getCid() + " : " + cellLocation.getLac();
textView.setText("Cell Info Logger\nCell Location\n"+desc);
logger.write(desc);
} // END onCellLocationChanged
当我执行此部分功能时,出现此错误: 不可转换的类型;无法将“android.telephony.CellIdentityGsm”转换为“android.telephony.CellLocation”
这让我觉得我根本无法进行类型转换,我需要另一个实现解决方案。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)