安卓:我如何获得所有可用的网络运营商的GSM信号强度 [英] Android: How do I get GSM signal strength for all available network operators

查看:444
本文介绍了安卓:我如何获得所有可用的网络运营商的GSM信号强度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个小应用程序来检查我区各网络运营商的信号强度。我目前运营商的信号是相当不稳定的,我想看看其他的GSM运营商的实力。

SOFAR我一直在使用的TelephonyManager并与onSignalStrengthsChanged回调,以获得当前的网络运营商的GSM信号强度的PhoneStateListener,但似乎这一类只给了我在网络的连接信号强度信息我的SIM卡。

我感兴趣的所有可用运营商的GSM信号强度测量。搜索网已就使用内部的android类模糊的暗示,但我还没有找到任何很好的例子这一点。

这是能打动我在获得所有可用的网络运营商的名单和他们的信号强度的任何答案是AP preaciated。

解决方案

也许这些报价和链接可以帮助您code自己的解决方案:

1:要获取可用网络提供商的列表(报价<一个href="http://stackoverflow.com/questions/3123697/how-to-get-a-list-of-available-network-providers#answer-3123904">How获得可用网络提供商的列表全):

  

由于Android是开源的我看了一下源代码,最后   发现了一些所谓的 INetworkQueryService 。我想你可以做   同为Android设置的实施以及与此互动   服务。通过NetworkSettings.java一些指导意见:

     
      
  • 的onCreate开始NetworkQueryService并结合它。
  •   
  • loadNetworksList()通知服务,以查询网络运营商。
  •   
  • INetworkQueryServiceCallback进行评估,如果活动EVENT_NETWORK_SCAN_COMPLETED有人提出,networksListLoaded会   所谓遍历可用的网络。
  •   

2:即使是一个快速阅读到<一个href="https://github.com/dzo/packages_apps_phone/blob/master/src/com/android/phone/NetworkSetting.java">NetworkSetting.java和<一href="https://github.com/dzo/packages_apps_phone/blob/master/src/com/android/phone/INetworkQueryService.aidl">INetworkQueryService接口,给了我们一个思路来实现自己的目标。

  • 连接在声明中的服务。

  / **
 *服务连接code为NetworkQueryService。
 *处理结合本地对象,这样我们就可以使工作
 *相应的服务呼叫。
 * /

/ **本地服务接口* /
私人INetworkQueryService mNetworkQueryService = NULL;

/ **服务连接* /
私人最终ServiceConnection mNetworkQueryServiceConnection =新ServiceConnection(){

    / **处理的本地对象绑定到服务任务* /
    公共无效onServiceConnected(组件名的className,服务的IBinder){
        如果(DBG)日志(创建的连接,结合本地服务。);
        mNetworkQueryService =((NetworkQueryService.LocalBinder)服务).getService();
        //只要它必然,运行查询。
        loadNetworksList();
    }

    / **处理清理本地绑定*的任务/
    公共无效onServiceDisconnected(组件名的className){
        如果(DBG)日志(连接断开,清洗局部的结合。);
        mNetworkQueryService = NULL;
    }
};
 

  • 的onCreate开始NetworkQueryService并结合它。

 意向意图=新的意图(这一点,NetworkQueryService.class);
...
startService(意向);
bindService(新意图(这一点,NetworkQueryService.class),mNetworkQueryServiceConnection,
                        Context.BIND_AUTO_CREATE);
 

  • loadNetworksList()通知服务,以查询网络运营商。

 私人无效loadNetworksList(){
...
//代表查询请求到服务。
尝试 {
    mNetworkQueryService.startNetworkQuery(mCallback);
}赶上(RemoteException的E){
}

displayEmptyNetworkList(假);
}
 

  • INetworkQueryServiceCallback评价:

  / **
 *本实施INetworkQueryServiceCallback的用于接收
 *从网络查询服务回调通知。
 * /
私人最终INetworkQueryServiceCallback mCallback =新INetworkQueryServiceCallback.Stub(){

    / **将消息查询完成后弯针队列。 * /
    公共无效onQueryComplete(名单&LT; OperatorInfo&GT; networkInfoArray,诠释状态){
        如果(DBG)日志(通知查询完成的消息循环。);
        消息味精= mHandler.obtainMessage(EVENT_NETWORK_SCAN_COMPLETED,
                状态,0,networkInfoArray);
        msg.sendToTarget();
    }
};
 

  • 如果事件EVENT_NETWORK_SCAN_COMPLETED有人提出,networksListLoaded将被调用来遍历可用的网络。

 私人无效networksListLoaded(名单&LT; OperatorInfo&GT;结果,INT状态){
    ...

    如果(状态!= NetworkQueryService.QUERY_OK){
        ...
        displayNetworkQueryFailed(状态);
        displayEmptyNetworkList(真正的);
    } 其他 {
        如果(结果!= NULL){
            displayEmptyNetworkList(假);
            ...
        } 其他 {
            displayEmptyNetworkList(真正的);
        }
    }
}
 

我希望它能帮助。我认为这是一个有趣的挑战,所以也许我给它一个尝试下一次我有一些空闲时间。祝你好运!

I am working on a little app to check the signal strength of various network operators in my area. My current operators signal is quite unstable and I want to look into the strength of other GSM operators.

Sofar I've been using the TelephonyManager and a PhoneStateListener with the onSignalStrengthsChanged call back to get the GSM Signal strength of the current network operator, but it seems that this class only gives me info on the signal strength of the network attached to my SIM card.

I'm interested in measurement of GSM signal strength of ALL available operators. Searching the net has given vague hints on using internal android classes, but I've not yet found any good examples on this.

Any answer that can move me on to get a list of all available network operators and their signal strength are appreaciated.

解决方案

Maybe these quotes and links can help you code your own solution:

1.- To get a list of available network providers (quoting How to get a list of available network providers? in full):

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.- Even a quick read to NetworkSetting.java and INetworkQueryService interface, gives us an idea to achieve your goal.

  • Connect the service in declaration.

/**
 * 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 starts the NetworkQueryService and binds it.

Intent intent = new Intent(this, NetworkQueryService.class);
...
startService (intent);
bindService (new Intent(this, NetworkQueryService.class), mNetworkQueryServiceConnection,
                        Context.BIND_AUTO_CREATE);

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

private void loadNetworksList() {
...    
// delegate query request to the service.
try {
    mNetworkQueryService.startNetworkQuery(mCallback);
} catch (RemoteException e) {
}

displayEmptyNetworkList(false); 
}

  • INetworkQueryServiceCallback is evaluated:

/**
 * 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();
    }
};

  • If the event "EVENT_NETWORK_SCAN_COMPLETED" was raised, networksListLoaded will be called to iterate over the available Networks.

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);
        }
    }
}

I hope it helps. I think it's an interesting challenge so maybe I'll give it a try next time I have some spare time. Good luck!

这篇关于安卓:我如何获得所有可用的网络运营商的GSM信号强度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆