android - 在有根的 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 创建热点时,它显示我没有互联网连接错误并且连接失败。
正如我所观察到的,热点正在打开,当我用手机搜索附近的热点时,我可以看到热点。
这里的主要问题我认为热点没有被激活。
我在这里做错了什么?
解决方案
推荐阅读
- android - 如何在 Android 设备处于锁定模式时接收/发送广播
- python - Pyqgis:编写自动化单元测试
- java - Android - 将日期转换为时间戳
- java - 安全地投射到
- github - github:“更新被拒绝,因为您当前分支的尖端落后”我该如何解决?
- apache-spark - Zeppelin Notebook 上默认用户创建 Spark 池
- c# - Elasticsearch.Net.UnexpectedElasticsearchClientException:在从 ES 获取数据期间
- java - 有没有办法在 JPA 存储库的 @Query 注释中使用常量(EnumType Ordinal)值?
- c# - 此请求无权执行此操作。Azure blobClient
- django - Sentry SDK - 如何使用新客户端进行 raven 测试调用?