检测BSSID不断变化 [英] Detect BSSID changes Constantly

查看:1029
本文介绍了检测BSSID不断变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应该Android应用程序的不断查看到该手机所连接的接入点的BSSID,知道手机将始终连接到一个网络,但可以连接到多个接入点(不同时,当然),因为建筑物大。我用一个BroadcastReceiver,但要检查手机是否得到了连接到不同的接入点,我不得不关闭该应用程序并再次运行它来获取更新的BSSID。我希望应用程序不断的检查和更新与新BSSID的UI没有我不必关闭应用程序,然后再次打开它。你有什么想法,我该怎么办呢?

I am developing an android application that is supposed to constantly check the BSSID of the access point to which the phone is connected, knowing that the phone will always be connected to one network but may connect to multiple access points (Not at the same time, of course) since the building is big. I used a BroadcastReceiver but to check whether the phone got connected to a different access point, I have to close the application and run it again to get the updated BSSID. I want the application to constantly check and update the UI with the new BSSID without me having to close the application and open it again. Do you have any idea how I can do that?

感谢您

推荐答案

我已经成功用这个在过去的监视WiFi连接的变化:

I have sucessfully used this in the past to monitor for WiFi connection changes:

public class NetworkChangeReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
        NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        // etc
    }
}
}

只要注册你的onResume(接收器),并在onPause(注销它),你应该是好去。

Just register your receiver in onResume() and unregister it in onPause() and you should be good to go.

@Override
protected void onResume() {
    super.onResume();       

    IntentFilter connectivityFilter = new IntentFilter();
    connectivityFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
    registerReceiver(your_broadcast_receiver, connectivityFilter);
}

这篇关于检测BSSID不断变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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