What should I do to tether WiFi on Android Things 3)?

Asked 2 years ago, Updated 2 years ago, 51 views

I tried using the code below, but it turned out to be SecurityException and could not be configured.
I set WRITE_SETTINGS for the manifest, but is it not possible to use it?

"Caused by: java.lang.SecurityException: com.example.androidthings.myproject was not granted this permission:android.permission.WRITE_SETTINGS."

private void wifiTetheringOn(){
    WifiManager wifi=(WifiManager) getSystemService(Context.WIFI_SERVICE);
    try{
        Method method=wifi.getClass().getMethod("setWifiAppEnabled", WifiConfiguration.class, boolean.class);
        Log.i(TAG, method.invoke(wifi, null, true).toString());
    } catch(Exceptione){
        Log.e(TAG, "error:", e);
    }
}

AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android: name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

Thank you for your cooperation

android raspberry-pi

2022-09-30 14:28

1 Answers

The security level of WRITE_SETTINGS should have changed since Android 6.0.
You should have explicit permission from the user.
It is listed in the Note of WRITE_SETTINGS in the API reference.
https://developer.android.com/reference/android/Manifest.permission.html

Understanding Permission Issues in WRITE_SETTINGS
I have a similar question below, and it seems that it has been solved.
https://stackoverflow.com/questions/32083410/cant-get-write-settings-permission


2022-09-30 14:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.