• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Wifi Not Enabled on HTC Desire

mist3r0

Newbie
Dec 12, 2009
19
0
Hello boys,

I'm a beginner android programmer.

In my application I want active wifi, but I've a problem when test my application on my HTC DESIRE.

This is The code that I've write:

Code:
if(cur.getString().equals("false"))
            if((wifiManager.getWifiState() != WifiManager.WIFI_STATE_DISABLED) && wifiManager.isWifiEnabled())
                 wifiManager.setWifiEnabled(false);
        else if(cur.getString().equals("true"))
               if((wifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED) && !wifiManager.isWifiEnabled())
                 wifiManager.setWifiEnabled(true);
The problem is that, if the Wifi is enabled my application turn off the wifi, but don't work if the wifi is disabled and I want enable.

NOTE: I've insert this permission in the manifest file

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

    <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
    
    <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"></uses-permission>
Why the Wifi not enabled?? Is a problem of Sense Interface? Can you help me?:thinking::thinking::thinking:
 
You should get used to adding brackets to your if statements.

As your indentation already indicates, your else if clause belongs to the inner if clause.

Try
Code:
if(cur.getString().equals("false")) {
            if((wifiManager.getWifiState() != WifiManager.WIFI_STATE_DISABLED) && wifiManager.isWifiEnabled())
                 wifiManager.setWifiEnabled(false);
}
else if(cur.getString().equals("true")) {
               if((wifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED) && !wifiManager.isWifiEnabled())
                 wifiManager.setWifiEnabled(true)
}
instead.
 
Upvote 0
Oh Thanks!!! :) This is a big mistake!!! :(

I've another question for you:

There is a method to directly enable gps without run this intent:

Code:
Intent in = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(in);

because thisi ntent bring me into setting menu and I do not want this!
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones