android 网络运营商,android - Android:如何获取所有可用网络运营商的GSM信号强度

我正在开发一个小应用程序,以检查我所在地区的各种网络运营商的信号强度。我目前的运营商信号非常不稳定,我想研究其他GSM运营商的实力。

Sofar我一直在使用TelephonyManager和PhoneStateListener以及onSignalStrengthsChanged回叫来获取当前网络运营商的GSM信号强度,但是似乎该类仅向我提供了附加到我的SIM卡上的网络的信号强度信息。

我对所有可用运营商的GSM信号强度的测量感兴趣。搜索网络已经给出了使用内部android类的模糊提示,但是我还没有找到任何很好的例子。

任何能使我继续前进的答案,都会列出所有可用的网络运营商及其信号强度。

最佳答案

也许这些引号和链接可以帮助您编写自己的解决方案:

1.-要获取可用网络提供商的列表(完整引用How to get a list of available network providers?):Since Android is open source I had a look at the sources and finally

found something called INetworkQueryService. I guess you can do the

same as the android settings implementation and interact with this

service. Some guidance through NetworkSettings.java:

onCreate starts the NetworkQueryService and binds it.

loadNetworksList() tells the service to query for network operators.

INetworkQueryServiceCallback is evaluated and if the event "EVENT_NETWORK_SCAN_COMPLETED" was raised, networksListLoaded will be

called to iterate over the available Networks.

2.-即使快速阅读NetworkSetting.java和INetworkQueryService interface,也可以使我们实现您的目标。

在声明中连接服务。

/**

* Service connection code for the NetworkQueryService.

* Handles the work of binding to a local object so that we can make

* the appropriate service calls.

*/

/** Local service interface */

private INetworkQueryService mNetworkQueryService = null;

/** Service connection */

private final ServiceConnection mNetworkQueryServiceConnection = new ServiceConnection() {

/** Handle the task of binding the local object to the service */

public void onServiceConnected(ComponentName className, IBinder service) {

if (DBG) log("connection created, binding local service.");

mNetworkQueryService = ((NetworkQueryService.LocalBinder) service).getService();

// as soon as it is bound, run a query.

loadNetworksList();

}

/** Handle the task of cleaning up the local binding */

public void onServiceDisconnected(ComponentName className) {

if (DBG) log("connection disconnected, cleaning local binding.");

mNetworkQueryService = null;

}

};

onCreate启动NetworkQueryService并将其绑定(bind)。

Intent intent = new Intent(this, NetworkQueryService.class);

...

startService (intent);

bindService (new Intent(this, NetworkQueryService.class), mNetworkQueryServiceConnection,

Context.BIND_AUTO_CREATE);

loadNetworksList()告诉服务查询网络运营商。

private void loadNetworksList() {

...

// delegate query request to the service.

try {

mNetworkQueryService.startNetworkQuery(mCallback);

} catch (RemoteException e) {

}

displayEmptyNetworkList(false);

}

评估INetworkQueryServiceCallback:

/**

* This implementation of INetworkQueryServiceCallback is used to receive

* callback notifications from the network query service.

*/

private final INetworkQueryServiceCallback mCallback = new INetworkQueryServiceCallback.Stub() {

/** place the message on the looper queue upon query completion. */

public void onQueryComplete(List networkInfoArray, int status) {

if (DBG) log("notifying message loop of query completion.");

Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_COMPLETED,

status, 0, networkInfoArray);

msg.sendToTarget();

}

};

如果引发了事件“EVENT_NETWORK_SCAN_COMPLETED”,则将调用networksListLoaded在可用网络上进行迭代。

private void networksListLoaded(List result, int status) {

...

if (status != NetworkQueryService.QUERY_OK) {

...

displayNetworkQueryFailed(status);

displayEmptyNetworkList(true);

} else {

if (result != null){

displayEmptyNetworkList(false);

...

} else {

displayEmptyNetworkList(true);

}

}

}

希望对您有所帮助。我认为这是一个有趣的挑战,所以下次有空的时候我可能会尝试一下。祝你好运!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值