7

嗨,我有以下读取网络/Wifi 状态的代码:

public String getMacAddress() {
    WifiManager wm = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
    return wm.getConnectionInfo().getMacAddress();
}

这抛出

Caused by: java.lang.SecurityException: WifiService: Neither user 10032 nor current process has android.permission.ACCESS_WIFI_STATE

public boolean is3G() {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    return !(connectivityManager.getNetworkInfo(
            ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || connectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED);
}

这抛出

Caused by: java.lang.SecurityException: ConnectivityService: Neither user 10032 nor current process has android.permission.ACCESS_NETWORK_STATE.

在有人告诉我权限之前,这是我的清单(相关部分):

<manifest> 
   <!-- usual tags for activitys... etc.. -->

    <uses-permission android:name="android.permission.WRITE_OWNER_DATA" />
    <uses-permission android:name="android.permission.READ_OWNER_DATA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <user-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <user-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest> 
4

2 回答 2

11

您拼错了最新的 2 个权限:

userR-permission 而不是 useS-permission

于 2011-05-17T14:12:42.830 回答
3

您的清单权限错误。

你有用户权限而不是使用权限

于 2011-05-17T14:13:22.557 回答