David Heisnam
David Heisnam

Reputation: 2491

Can't use ACCESS_WIFI_STATE and CHANGE_WIFI_STATE pernissions together

In my Android app, I need to check if WiFi is on in one part and also to change the WiFi state in another.

I can either use ACCESS_WIFI_STATE permission to check the state or use CHANGE_WIFI_STATE to change the WiFi state but not both permissions together. If I include both permissions in the Manifest, I get a duplicate attribute error. Why is this?

I've included the Manifest, just in case.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.examlple.wifiautotoggle"
android:versionCode="1"
android:versionName="1.0" >
    <uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="19" />
    <uses-permission
    android:name="android.permission.ACCESS_WIFI_STATE"
    android:name="android.permission.CHANGE_WIFI_STATE" />
    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
        <activity
        android:label="@string/app_name"
        android:name=".MainActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service
        android:name="com.example.wifiautotoggle.WifiToggleService" />
    </application>

</manifest>

Upvotes: 1

Views: 2015

Answers (1)

J. Steen
J. Steen

Reputation: 15578

You need one permission per permission-element.

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

The error you get is because you've duplicated the android:name attribute in one user-permission element.

From http://developer.android.com/guide/topics/manifest/manifest-intro.html

Multiple values

If more than one value can be specified, the element is almost always repeated, rather than listing multiple values within a single element. For example, an intent filter can list several actions.

Upvotes: 2

Related Questions