奥利奥Wifi连接 [英] Oreo Wifi Connectivity

查看:84
本文介绍了奥利奥Wifi连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个物联网应用程序,其中存在一个登机过程,即用户连接到没有Internet连接的接入点,配置设备,然后连接到他的家庭Wifi网络.

I am working on an IoT app in which there is an on boarding process where the user connects to an access point, which has not internet connectivity, configure the device and then connects to his home Wifi network.

Android 8设备已引起一些问题,与访问点断开连接并重新连接到先前配置的网络.我假设这与Android 8中引入的连接更新有关,该更新来自

Android 8 devices have been causing some problems, disconnecting from the access point and reconnecting to a previously configured network. I am assuming this is related to the connectivity update which was introduced in Android 8, from section Seamless Connectivity in this link:

在兼容的设备上,当电量过高时会自动激活Wi-Fi 已保存质量的网络就在附近.

On compatible devices, automatic activation of Wi-Fi when a high quality saved network is nearby.

我的问题是如何禁用此行为,因为我需要保持连接到接入点,而没有Internet连接,并完成登机流程.

My question is how to disable this behaviour as I need to stay connected to the access point, without internet connectivity, and finish the on Boarding process.

推荐答案

我遇到了同样的问题.这是我在Android 8+设备中解决此问题的方法. 1.由于Android 8+设备会在WiFI和Cellular设备之间自动切换.我删除了下面的代码.即强制强制使用wifi的代码.

I had same issue. This is how I fix this issue in Android 8+ devices. 1. Since Android 8+ devices auto switch between WiFI and Cellular devices. I removed below code. i.e. Code to force move to wifi.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    NetworkRequest.Builder request = new NetworkRequest.Builder();
    Log.i("forceCellularConnection","request WIFI enable");
    request.addCapability(NetworkCapabilities.TRANSPORT_WIFI);
    connectivityManager.requestNetwork(request.build(), new ConnectivityManager.NetworkCallback() {
          @Override
          public void onAvailable(Network network) {
               if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                      connectivityManager.setProcessDefaultNetwork(network);

                      connectivityManager.bindProcessToNetwork(network);
                }
           }
     });

}

  1. 还添加了以下代码,以便在建立新连接之前忘记wifi连接.设备断开WiFI连接需要花费一些时间.因此,我在连接到新的WIFI SSID之前增加了延迟.

  1. Also added below code to forget wifi connection before we make new connection. It takes some time for device to disconnect WiFI. So I added delay before connecting to new WIFI SSID.

this.wifiManager.disableNetwork(configuration.networkId);
this.wifiManager.removeNetwork(configuration.networkId);
this.wifiManager.saveConfiguration(); // Not needed in API level 26 and above

我尝试并帮助我进行连接工作的解决方法如下:就我而言,我还必须连接没有互联网的WiFi.它是对等连接.

Workaround which I tried and helped me making connection work are below: In my case also I have to connect WiFi which doesn't have internet on it. Its a peer to peer connection.

  1. 我进行了2-3次连接尝试

  1. I Made 2-3 attempts for connection

new CountDownTimer(16000, 2000) {

  • 我还写了下面的广播接收器来检查WiFI的状态.然后建立连接.

  • Also I have written below broadcast receiver to check the state of WiFI. And then made the connection.

    private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() 
    {
        @Override
        public void onReceive(Context context, Intent intent) {
    
            final String action = intent.getAction();
    
            Log.d("WifiReceiver", ">>>>SUPPLICANT_STATE_CHANGED_ACTION<<<<<<");
            SupplicantState supl_state = ((SupplicantState) intent
                    .getParcelableExtra(WifiManager.EXTRA_NEW_STATE));
            switch (supl_state) {
            case ASSOCIATED:
                Log.i("SupplicantState", "ASSOCIATED");
                // authMsg = "ASSOCIATED";
                break;
            case ASSOCIATING:
                // authMsg = "ASSOCIATING";
                Log.i("SupplicantState", "ASSOCIATING");
                break;
            case AUTHENTICATING:
                // authMsg = "AUTHENTICATING";
                Log.i("SupplicantState", "Authenticating...");
                break;
            case COMPLETED:
                authMsg = "CONNECTED";
                Log.i("SupplicantState", "Connected");
                 final ConnectivityManager connection_manager =
                 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    
                NetworkRequest.Builder request = new NetworkRequest.Builder();
                request.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
    
                connection_manager.registerNetworkCallback(request.build(), new ConnectivityManager.NetworkCallback() {
    
                    @Override
                    public void onAvailable(Network network) {
                        ConnectivityManager.setProcessDefaultNetwork(network);
                    }
                });
                break;
            case DISCONNECTED:
    

  • 这篇关于奥利奥Wifi连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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