The*_*rtz 41 android gsm operators signal-strength
我正在开发一个小应用来检查我所在地区的各种网络运营商的信号强度.我目前的操作员信号非常不稳定,我想研究其他GSM运营商的实力.
Sofar我一直在使用TelephonyManager和带有onSignalStrengthsChanged回拨的PhoneStateListener来获取当前网络运营商的GSM信号强度,但似乎这个类只给我关于连接到我的SIM卡的网络信号强度的信息.
我对测量所有可用运营商的GSM信号强度感兴趣.搜索网络给出了使用内部android类的模糊提示,但我还没有找到任何好的例子.
任何能够让我获得所有可用网络运营商列表及其信号强度的答案都是适用的.
Ale*_*ado 23
也许这些引号和链接可以帮助您编写自己的解决方案:
1.-获取可用网络提供商列表(引用如何获取可用网络提供商列表?):
由于Android是开源的,我查看了源代码,最后发现了一些名为INetworkQueryService的东西.我想你可以像android设置实现一样做,并与此服务进行交互.通过NetworkSettings.java的一些指导:
- onCreate启动NetworkQueryService并绑定它.
- loadNetworksList()告诉服务查询网络运营商.
- 评估INetworkQueryServiceCallback,如果引发了事件"EVENT_NETWORK_SCAN_COMPLETED",将调用networksListLoaded来迭代可用的网络.
2.-即使快速阅读NetworkSetting.java和INetworkQueryService接口,我们也可以实现您的目标.
Run Code Online (Sandbox Code Playgroud)/** * 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; } };
Run Code Online (Sandbox Code Playgroud)Intent intent = new Intent(this, NetworkQueryService.class); ... startService (intent); bindService (new Intent(this, NetworkQueryService.class), mNetworkQueryServiceConnection, Context.BIND_AUTO_CREATE);
Run Code Online (Sandbox Code Playgroud)private void loadNetworksList() { ... // delegate query request to the service. try { mNetworkQueryService.startNetworkQuery(mCallback); } catch (RemoteException e) { } displayEmptyNetworkList(false); }
Run Code Online (Sandbox Code Playgroud)/** * 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<OperatorInfo> 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(); } };
Run Code Online (Sandbox Code Playgroud)private void networksListLoaded(List<OperatorInfo> result, int status) { ... if (status != NetworkQueryService.QUERY_OK) { ... displayNetworkQueryFailed(status); displayEmptyNetworkList(true); } else { if (result != null){ displayEmptyNetworkList(false); ... } else { displayEmptyNetworkList(true); } } }
我希望它有所帮助.我认为这是一个有趣的挑战,所以也许下次我有空余时间试一试.祝好运!
归档时间: |
|
查看次数: |
36503 次 |
最近记录: |