1

I was creating an app that will create and enable wifi hotspot of my mobile using the given credential

public static boolean setHotspotName(String ssid, String pass, Context context) {
    try {
        WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
        Method getConfigMethod = wifiManager.getClass().getMethod("getWifiApConfiguration");
        WifiConfiguration wifiConfig = (WifiConfiguration) getConfigMethod.invoke(wifiManager);

        wifiConfig.SSID = ssid;

        Method setConfigMethod = wifiManager.getClass().getMethod("setWifiApConfiguration", WifiConfiguration.class);
        setConfigMethod.invoke(wifiManager, wifiConfig);
        return true;
    }
    catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

getting this error

W/System.err: Caused by: java.lang.SecurityException: App not allowed to read 
or update stored WiFi Ap config (uid = 10492)
Tamir Abutbul
  • 6,886
  • 7
  • 24
  • 48

1 Answers1

-1

Try to add this permission in the manifest :

</permission android:name="android.permission.OVERRIDE_WIFI_CONFIG"
        tools:ignore="ProtectedPermissions" />
Shay Kin
  • 2,311
  • 3
  • 13
  • 20