检查Wifi时的java.lang.Securityexception

时间:2012-09-27 11:54:20

标签: android android-wifi

private void requestNewCoordinates() {          

        final WifiManager wfManager = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
             if (manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
                && wfManager.isWifiEnabled()) {
             }
}

  <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

wfManager.isWifiEnabled() - java.lang.Securityexception

告诉我什么是错的......以及如何解决问题

https://stackoverflow.com/a/9325388/1568164 - 它有效

3 个答案:

答案 0 :(得分:1)

在清单中提供此权限

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

答案 1 :(得分:0)

确保您已在清单文件中声明ACCESS_NETWORK_STATE权限。

答案 2 :(得分:0)

在清单

中授予权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />