Exception reading Wifi/3G State
Asked Answered
B

2

7

Hi I have the following code that reads Network/Wifi state:

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

This throws

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

And

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);
}

This throws

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

Before someone tell me about the permissions, that is my Manifest (the relevant part):

<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> 
Buller answered 17/5, 2011 at 14:9 Comment(0)
T
11

You've mispelled the latest 2 permissions:

useR-permission instead of useS-permission

Tailband answered 17/5, 2011 at 14:12 Comment(0)
K
3

Your manifest permissions are wrong.

you have user-permission instead of uses-permission

Karnak answered 17/5, 2011 at 14:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.