问题
Given this code:
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
...and this line in the manifest:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
I still get the exception:
WifiService: Neither user 10057 nor current process has android.permission.ACCESS_WIFI_STATE.
I am debugging on a Xoom, Honeycomb 3.1.
If there is any other info that is needed, please ask.
EDIT: added Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.WiFiDemo"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="12" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:label="@string/app_name" android:name="WiFiDemo">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
回答1:
Try adding
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
edit:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.WiFiDemo"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="12" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:label="@string/app_name" android:name="WiFiDemo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
回答2:
try this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.WiFiDemo"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="12" />
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:label="@string/app_name" android:name="WiFiDemo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
来源:https://stackoverflow.com/questions/7808526/getconnectioninfo-exception