首页 > 解决方案 > 在有根的 7.x 设备上以编程方式激活热点

问题描述

几天来,我一直在努力在有根的 android 设备中打开热点。我能够创建和打开热点。我用来创建 Wifi 配置的代码:

if (!Settings.System.canWrite(getApplicationContext())) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + getPackageName()));
            startActivityForResult(intent, 200);
        }

WifiConfiguration conf = new WifiConfiguration();
conf.SSID =  ssid;
conf.preSharedKey = encodedKey;
conf.allowedKeyManagement.set(4);
conf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

并打开热点:

try {
      WifiManager mWifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);

      if (enabled) 
      {
         mWifiManager.setWifiEnabled(false);
      }
      mWifiManager.addNetwork(conf);

      return (Boolean)  mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class).invoke(mWifiManager, conf, enabled);

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

到目前为止一切正常,但是当我尝试连接以使用我的 iPhone 创建热点时,它显示我没有互联网连接错误并且连接失败。
正如我所观察到的,热点正在打开,当我用手机搜索附近的热点时,我可以看到热点。

这里的主要问题我认为热点没有被激活。
我在这里做错了什么?

标签: androidhotspotrooted-device

解决方案


推荐阅读