当我尝试通过以下代码启用 wifi 网络共享时,它会抛出异常
com java.lang.reflect.Method.invoke(Native Method) 处的 java.lang.reflect.InitationTargetException ......
....未授予此权限:android.permission.WRITE_SETTINGS
但这在android 6.0及以下版本中工作正常。也尝试过给予android.permission.WRITE_SETTINGS too.
android 6.1 访问wifiAP有限制吗?
我附上了用于启用热点的代码示例。
WifiConfiguration netConfig = new WifiConfiguration();
netConfig.SSID = ssId;
netConfig.preSharedKey = passkey;
netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
try {
boolean apstatus = (Boolean) method.invoke(wifiManager, netConfig, true);
for (Method isWifiApEnabledmethod : wmMethods) {
if (isWifiApEnabledmethod.getName().equals("isWifiApEnabled")) {
while (!(Boolean) isWifiApEnabledmethod.invoke(wifiManager)) {}
for (Method method1 : wmMethods) {
if (method1.getName().equals("getWifiApState")) {
int apstate;
apstate = (Integer) method1.invoke(wifiManager);
Log.i(TAG, "Apstate ::: " + apstate);
}
}
}
}
if (apstatus) {
Log.d(TAG, "Access Point created");
} else {
Log.d(TAG, "Access Point creation failed");
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
我认为Android M不支持以编程方式创建热点。您可以将 Marshmallow 用户带到设置页面自行创建热点。下面的代码将帮助您进入设置页面。
startActivity(
new Intent(Settings.ACTION_SETTINGS));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)