2

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
  • 7,301
  • 7
  • 25
  • 53

2 Answers2

0

must add android:sharedUserId="android.uid.system" and add platform.keystore create by system level –

Changing Android hotspot settings

Snippet from framework AndroidManifest.xml

Not for use by third-party applications. -->

This means that your application needs to be signed by the platform key or be privileged to use this API.

Haliluya
  • 1
  • 1
  • must add android:sharedUserId="android.uid.system" and add platform.keystore create by system level – Haliluya Nov 21 '22 at 08:28
-1

Try to add this permission in the manifest :

</permission android:name="android.permission.OVERRIDE_WIFI_CONFIG"
        tools:ignore="ProtectedPermissions" />
Shay Kin
  • 2,539
  • 3
  • 15
  • 22