Security exception by accessing the wifi in android

前端 未结 3 1220
没有蜡笔的小新
没有蜡笔的小新 2021-01-11 10:28

Please see the following code

    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    if (wifi.isWifiEnabled() == false)
    {
        Toast.mak         


        
相关标签:
3条回答
  • 2021-01-11 10:35

    To be able to access the wifi you need android:name="android.permission.ACCESS_WIFI_STATE" as you already know.

    If you are enabling or disabling the wifi connection you are also going to need both permissions: ACCESS_WIFI_STATE and CHANGE_WIFI_STATE

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

    That should do it for you.

    0 讨论(0)
  • 2021-01-11 10:35

    It should be "uses-permission" rather than "user-permission". spelling is wrong

    0 讨论(0)
  • 2021-01-11 10:46

    add following lines

        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
        <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    

    hope they help!

    0 讨论(0)
提交回复
热议问题