getConnectionInfo() exception

孤人 提交于 2019-12-01 23:55:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!