Tôi đã cố gắng tạo điểm phát sóng chia sẻ kết nối wifi trong Android Marshmallow bằng cách sử dụng mã sau.Làm thế nào để tạo điểm truy cập Internet tethering trong Android Marshmallow?
public class WifiAccessManager {
private static final String SSID = "1234567890abcdef";
public static boolean setWifiApState(Context context, boolean enabled) {
//config = Preconditions.checkNotNull(config);
try {
WifiManager mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (enabled) {
mWifiManager.setWifiEnabled(false);
}
WifiConfiguration conf = getWifiApConfiguration();
mWifiManager.addNetwork(conf);
return (Boolean) mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class).invoke(mWifiManager, conf, enabled);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public static WifiConfiguration getWifiApConfiguration() {
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = SSID;
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
return conf;
}
}
Nhưng nó được thể hiện vấn đề cho phép sau. .
java.lang.SecurityException: googleplus.tarun.info.hotspotcreation was not granted either of these permissions: android.permission.CHANGE_NETWORK_STATE, android.permission.WRITE_SETTINGS.
Nhưng tôi đã thêm chúng vào tệp kê khai. .
Làm cách nào để giải quyết sự cố?