Android 5.0 Lollipop and 4.4 KitKat ignores my WiFi network, enableNetwork() is useless

前端 未结 3 1356
情歌与酒
情歌与酒 2020-12-24 12:49

My app connect directly to a hardware device that act as an access point (with no access to internet).

I can\'t connect because Android 5.0 automat

3条回答
  •  清歌不尽
    2020-12-24 13:40

    You can try to use new Lollipop API ConnectivityManager.requestNetwork(), supposedly like this:

    ConnectivityManager cm = (ConnectivityManager) Context.getSystemService(Context.CONNECTIVITY_SERVICE);
    cm.requestNetwork(new NetworkRequest.Builder()
                      .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
                      .setNetworkSpecifier("XX:XX:XX:XX:XX:XX")
                      .build(),
                      new ConnectivityManager.NetworkCallback() {
                          void onAvailable(Network network) {
    
                          }
                      });
    

    where XX:XX:XX:XX:XX:XX is your WiFi SSID. I'm not sure about it's format, and if it's used at all, I did not find any references to setNetworkSpecifier inside Android sources, except for the NetworkCapabilities class.

提交回复
热议问题