作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过传递来捕获单元 ID。我成功获得了最初连接到我手机的手机ID。但是,我无法准确解释这一点,似乎不同步。我漫游了好几次,但它总是返回第一个小区 ID。
public class MainActivity extends Activity {
private TextView textView;
private GsmCellLocation gsmCellLocation;
private TelephonyManager telephonyManager;
private String cId = "", lac = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
gsmCellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
telephonyManager.listen(listener,
PhoneStateListener.LISTEN_CELL_LOCATION);
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case 1:
updateText();
}
}
};
public String updateLocation() {
cId = Integer.toHexString(gsmCellLocation.getCid());
lac = Integer.toString(gsmCellLocation.getLac());
return "cId: " + cId + "\nLac: " + lac + "\n===============\n";
}
public void updateText() {
Toast.makeText(getApplicationContext(), updateLocation(),
Toast.LENGTH_SHORT).show();
textView.append(updateLocation());
}
private PhoneStateListener listener = new PhoneStateListener() {
@Override
public void onCellLocationChanged(CellLocation location) {
// TODO Auto-generated method stub
super.onCellLocationChanged(location);
handler.sendEmptyMessage(1);
}
};
}
最佳答案
你不应该添加:
MainActivity.this.gsmCellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
在 onCellLocationChanged 方法内部?
关于java - GsmCellLocation 返回相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29920433/
我正在尝试通过传递来捕获单元 ID。我成功获得了最初连接到我手机的手机ID。但是,我无法准确解释这一点,似乎不同步。我漫游了好几次,但它总是返回第一个小区 ID。 public class MainA
在我的应用程序中,我使用 GsmCellLocation 类来查找特定实例的小区 ID 和 lac。 我简单地定义了类并通过 TextView 将相应的属性显示到 Activity 。 我使用的代码部
我成功获取了 GsmCellLocation 和相关的 cid 和 lac 信息,但服务小区的 PSC(主扰码)总是返回初始值 -1。谁能得到服务小区的真实PSC值? telephonyManager
我遇到了这个错误: E/AndroidRuntime: FATAL EXCEPTION: main
我是一名优秀的程序员,十分优秀!