当我尝试从以下代码启用wifi网络共享时,它会抛出异常
java.lang.reflect.Method.invoke(Native Method)中的java.lang.reflect.InvocationTargetException ...
....未授予此权限:android.permission.WRITE_SETTINGS
但这在Android 6.0及以下版本中运行良好。 并尝试给予android.permission.WRITE_SETTINGS 。
在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();
}