Android:我如何获得所有可用networking运营商的GSM信号强度
我正在开发一个小应用程序来检查我所在地区的各种networking运营商的信号强度。 我目前的运营商信号是相当不稳定的,我想看看其他GSM运营商的实力。
Sofar我一直在使用TelephonyManager和一个PhoneStateListener和onSignalStrengthsChangedcallback来获得当前networking运营商的GSM信号强度,但是这个类似乎只给了我连接到我的SIM卡的networking的信号强度。
我有兴趣测量所有可用的运营商的GSM信号强度。 searchnetworking已经给出了使用内部android类的模糊提示,但我还没有find任何好的例子。
任何能让我感动的答案都可以得到所有可用networking运营商的列表及其信号强度。
也许这些引用和链接可以帮助你编写你自己的解决scheme:
1.-要获得可用networking提供商列表(请参阅如何获得可用networking提供商列表 ) ?
由于Android是开源的,所以我查看了源代码并最终find了一个名为INetworkQueryService的东西。 我想你可以做同样的android设置实现,并与此服务进行交互。 通过NetworkSettings.java的一些指导:
- onCreate启动NetworkQueryService并绑定它。
- loadNetworksList()通知服务查询networking运营商。
- INetworkQueryServiceCallback被评估,如果事件“EVENT_NETWORK_SCAN_COMPLETED”被引发,networksListLoaded将被调用来迭代可用的networking。
2.甚至可以快速读取NetworkSetting.java和INetworkQueryService接口 ,为我们提供一个实现您的目标的想法。
- 在声明中连接服务。
/** * 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并绑定它。
Intent intent = new Intent(this, NetworkQueryService.class); ... startService (intent); bindService (new Intent(this, NetworkQueryService.class), mNetworkQueryServiceConnection, Context.BIND_AUTO_CREATE);
- loadNetworksList()通知服务查询networking运营商。
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<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(); } };
- 如果发生事件“EVENT_NETWORK_SCAN_COMPLETED”,将调用networksListLoaded来迭代可用的networking。
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); } } }
我希望它有帮助。 我认为这是一个有趣的挑战,所以下次有空闲时我可以试一试。 祝你好运!
private final PhoneStateListener phoneStateListener = new PhoneStateListener() { @Override public void onCallForwardingIndicatorChanged(boolean cfi) { super.onCallForwardingIndicatorChanged(cfi); } @Override public void onCallStateChanged(int state, String incomingNumber) { //checkInternetConnection(); String callState = "UNKNOWN"; switch (state) { case TelephonyManager.CALL_STATE_IDLE: callState = "IDLE"; break; case TelephonyManager.CALL_STATE_RINGING: callState = "Ringing (" + incomingNumber + ")"; break; case TelephonyManager.CALL_STATE_OFFHOOK: callState = "Offhook"; break; } Log.i("Phone Stats", "onCallStateChanged " + callState); super.onCallStateChanged(state, incomingNumber); } @Override public void onCellLocationChanged(CellLocation location) { String cellLocationString = location.toString(); super.onCellLocationChanged(location); } @Override public void onDataActivity(int direction) { String directionString = "none"; switch (direction) { case TelephonyManager.DATA_ACTIVITY_IN: directionString = "IN"; break; case TelephonyManager.DATA_ACTIVITY_OUT: directionString = "OUT"; break; case TelephonyManager.DATA_ACTIVITY_INOUT: directionString = "INOUT"; break; case TelephonyManager.DATA_ACTIVITY_NONE: directionString = "NONE"; break; default: directionString = "UNKNOWN: " + direction; break; } Log.i("Phone Stats", "onDataActivity " + directionString); super.onDataActivity(direction); } @Override public void onDataConnectionStateChanged(int state,int networktype) { String connectionState = "Unknown"; switch (state ) { case TelephonyManager.DATA_CONNECTED : connectionState = "Connected"; break; case TelephonyManager.DATA_CONNECTING: connectionState = "Connecting"; break; case TelephonyManager.DATA_DISCONNECTED: connectionState = "Disconnected"; break; case TelephonyManager.DATA_SUSPENDED: connectionState = "Suspended"; break; default: connectionState = "Unknown: " + state; break; } super.onDataConnectionStateChanged(state); Log.i("Phone Stats", "onDataConnectionStateChanged " + connectionState); } @Override public void onMessageWaitingIndicatorChanged(boolean mwi) { super.onMessageWaitingIndicatorChanged(mwi); } @Override public void onServiceStateChanged(ServiceState serviceState) { String serviceStateString = "UNKNOWN"; switch (serviceState.getState()) { case ServiceState.STATE_IN_SERVICE: serviceStateString = "IN SERVICE"; break; case ServiceState.STATE_EMERGENCY_ONLY: serviceStateString = "EMERGENCY ONLY"; break; case ServiceState.STATE_OUT_OF_SERVICE: serviceStateString = "OUT OF SERVICE"; break; case ServiceState.STATE_POWER_OFF: serviceStateString = "POWER OFF"; break; default: serviceStateString = "UNKNOWN"; break; } Log.i("Phone Stats", "onServiceStateChanged " + serviceStateString); super.onServiceStateChanged(serviceState); } @Override public void onSignalStrengthChanged(int asu) { Log.i("Phone Stats", "onSignalStrengthChanged " + asu); setSignalLevel( asu); super.onSignalStrengthChanged(asu); } private void setSignalLevel(int level) { int sLevel = (int) ((level / 31.0) * 100); Log.i("signalLevel ", "" + sLevel); } };
由于我没有50点声望点,这是我对这个主题的search结果:
亚历杭德罗科罗拉多的解决scheme似乎是好的。 但问题是,用于实现它的类是为android系统应用程序保留的,即与系统签名的应用程序使用相同的签名密钥。
怎么可能呢? 我find了两个方法来实现这一点。
第一个是在任何制造商的公司里找工作,签署他们的NDA,但呃,这不是一个很好的解决scheme。 特别是随着应用程序实施和使用这个密钥签名将只能在设备从compagny …
第二个,更愉快,但我警告你,这不是一件容易的事,就是制作你自己的ROM。 您必须创build您的应用程序,将其插入到您的ROM的/ system / app /目录中,并重新编译它以使用新系统刷新您的设备。 但是还有一个问题,我还没有回答,是无法识别的ROM签名的问题。 我认为避免这个问题的最好方法是在你将要使用的恢复中添加你的ROM签名密钥。
这就是我在这一点,也许你可以find这些研究有用的,我希望如此! 我会再回来,如果我find更多的信息给你们。 再见。
创build一个PhoneStateListener并处理onSignalStrengthChangedcallback。 当你的应用程序初始化时,它应该给你一个初始通知。 这是1.x. 在2.x中,这是一个开放的问题 。