令人吃惊的是,HotSpot不适用于Android 11

令人吃惊的是,HotSpot不适用于Android 11,android,android-11,Android,Android 11,随信附上我在安卓11(三星Galaxy A71)中面临的本地热点问题 当我们第一次启动它时,它进入内部,日志显示它生成了本地热点以及名称和密码,但实际上它没有启动。在随后的尝试中,它甚至不进入onStarted()函数的内部 任何帮助都将不胜感激 @RequiresApi(api = Build.VERSION_CODES.O) public void createLocalHotspot() { WifiManager manager = (WifiManager) mApplicat

随信附上我在安卓11(三星Galaxy A71)中面临的本地热点问题

当我们第一次启动它时,它进入内部,日志显示它生成了本地热点以及名称和密码,但实际上它没有启动。在随后的尝试中,它甚至不进入onStarted()函数的内部

任何帮助都将不胜感激

@RequiresApi(api = Build.VERSION_CODES.O)
public void createLocalHotspot() {
    WifiManager manager = (WifiManager) mApplicationContext.getSystemService(Context.WIFI_SERVICE);

    /*//If Wifi is ON then switch it OFF
    if (manager.isWifiEnabled()) {
        manager.isWifiEnabled(false);
    }*/

    try {
        Log.d("DynamicRingOfFire", ": " + manager);
        //previousNetConfig = getHotSpotConfig();

        if (ActivityCompat.checkSelfPermission(mApplicationContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
        &&  ActivityCompat.checkSelfPermission(mApplicationContext, Manifest.permission.CHANGE_WIFI_STATE) == PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.

            if(manager.isWifiEnabled())
                manager.setWifiEnabled(false);

            manager.startLocalOnlyHotspot(new WifiManager.LocalOnlyHotspotCallback() {

                @Override
                public void onStarted(WifiManager.LocalOnlyHotspotReservation reservation) {
                    super.onStarted(reservation);
                    Log.d("DynamicRingOfFire", "Wifi Hotspot is on now");
                    mReservation = reservation;
                    WifiConfiguration mWifiConfig = mReservation.getWifiConfiguration();

                    Log.d("DynamicRingOfFire", "BSSID:" + mWifiConfig.BSSID);
                    Log.d("DynamicRingOfFire", "presharedkey:" + mWifiConfig.preSharedKey);
                    Log.d("DynamicRingOfFire", "SSID:" + mWifiConfig.SSID);

                    String data = "ConnectWIFI" + Constants.SPLIT_BY_COMMA + mWifiConfig.SSID + Constants.SPLIT_BY_COMMA + mWifiConfig.preSharedKey + Constants.SPLIT_BY_COMMA + "Hotspot";
                    Log.d("DynamicRingOfFire:", data);
                    MessageSender.getInstance().sendCriticalData(data, false, 4);
                }

                @Override
                public void onStopped() {
                    super.onStopped();
                    if (mReservation != null) {
                        mReservation.close();
                        mReservation = null;
                    }

                    Log.d("DynamicRingOfFire", "onStopped: ");
                }

                @Override
                public void onFailed(int reason) {
                    super.onFailed(reason);
                    if (mReservation != null) {
                        mReservation.close();
                        mReservation = null;
                    }
                    Log.d("DynamicRingOfFire", "onFailed: " + reason);
                }
            }, new Handler());
            return;
        }
        else
            Log.d("DynamicRingOfFire", "Required permissions not there");

    } catch (Exception e) {
        Log.d("Exception", "" + e);
    }

}
谢谢, 瓦希姆队