android 基站信号强度,Android获取基站信号强度问题?请看代码

public class MainActivity extends AppCompatActivity {

private static final String TAG = "GSMCellLocationActivity";

TelephonyManager telephonyManager;

MyPhoneStateListener MyListener;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

final TextView textView1 = (TextView) findViewById(R.id.text1);

final TextView textView2 = (TextView) findViewById(R.id.text2);

Button button= (Button) findViewById(R.id.button1);

telephonyManager= (TelephonyManager) MainActivity.this.getSystemService(Context.TELEPHONY_SERVICE);

MyListener = new MyPhoneStateListener();

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String operator = telephonyManager.getNetworkOperator();

/**通过operator获取 MCC 和MNC */

int mcc = Integer.parseInt(operator.substring(0, 3));

int mnc = Integer.parseInt(operator.substring(3));

GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();

/**通过GsmCellLocation获取中国移动和联通 LAC 和cellID */

int lac = location.getLac();

int cellid = location.getCid();

System.out.println("**"+mcc+"A"+mnc+"A"+lac+"A"+cellid);

textView1.setText("国家编号:"+mcc+"运营商编号:"+mnc+"LAC:"+lac+"CellID:"+cellid);

List<CellInfo> infos = telephonyManager.getAllCellInfo();

**// List<NeighboringCellInfo> infos = telephonyManager.getNeighboringCellInfo();

//这个方法在使用时,size一直为0,是为什么?**

StringBuffer sb = new StringBuffer("总数 : " + infos.size() + "\n");

for (CellInfo info1 : infos) { // 根据邻区总数进行循环

//  sb.append(" LAC : " + info1.getLac()); // 取出当前邻区的LAC

//  sb.append(" CID : " + info1.getCid()); // 取出当前邻区的CID

sb.append(" CID : " + info1.toString()); // 取出当前邻区的CID

//  sb.append(" BSSS : " + (-113 + 2 * info1.getRssi()) + "\n"); // 获取邻区基站信号强度

}

Log.i(TAG, " 获取邻区基站信息:" + sb.toString());

textView2.setText(sb.toString());

}

});

telephonyManager.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

// telephonyManager.listen(celllistener, PhoneStateListener.LISTEN_CELL_LOCATION); // 基站位置的变化

}

private class MyPhoneStateListener extends PhoneStateListener

{

/* Get the Signal strength from the provider, each tiome there is an update  从得到的信号强度,每个tiome供应商有更新*/

@Override

public void onSignalStrengthsChanged(SignalStrength signalStrength)

{

super.onSignalStrengthsChanged(signalStrength);

**if (signalStrength.getGsmSignalStrength() != 99) {

Toast.makeText(getApplicationContext(),

"Go to Firstdroid!!! GSM Cinr = " + String.valueOf(signalStrength.getGsmSignalStrength() * 2 - 113) + "dbM", Toast.LENGTH_SHORT).show();

//这里toast的数据是基站信号强度吗?

//手机信号强度和基站信号强度一样吗?

System.out.println("****" + String.valueOf(signalStrength.getGsmSignalStrength() * 2 - 113));**

}

}

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值