gpt4 book ai didi

java - GsmCellLocation 返回相同的值

转载 作者:行者123 更新时间:2023-12-01 11:36:34 25 4
gpt4 key购买 nike

我正在尝试通过传递来捕获单元 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com